ztellman / automat

better automata through combinators

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

reducers for actions on overlapping unions are not called

domkm opened this issue · comments

(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