ztellman / automat

better automata through combinators
588 stars 50 forks source link

reducers for actions on overlapping unions are not called #6

Closed domkm closed 10 years ago

domkm commented 10 years ago
(require '[automat.core :as a]

(-> (a/or (a/interpose-$ :x [1 2 3])
          (a/interpose-$ :y [1 2 9]))
    (a/compile {:reducers {:x #(update-in %1 [:x] conj %2)
                           :y #(update-in %1 [:y] conj %2)}})
    (a/find {:x [] :y []} [1 2 3])
    :value)
;=>  {:x [3] :y [1 2]}

I would expect the reduction value to be {:x [1 2 3] :y [1 2]}.

It looks like only actions attached to the last union are triggered when the unions overlap.

(-> (a/or (a/interpose-$ :y [1 2 9]) ; :y actions will be replaced by overlapping :x actions
          (a/interpose-$ :x [1 2 3]))
    (a/compile {:reducers {:x #(update-in %1 [:x] conj %2)
                           :y #(update-in %1 [:y] conj %2)}})
    (a/find {:x [] :y []} [1 2 3])
    :value)
;=> {:x [1 2 3], :y []}
; no :y actions trigger