Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
makeTransducer :
-> (Step s acc b -> Step s (s', acc) a)
-> (Step s acc b -> s' -> acc -> State s acc)
-> Transducer acc s (s', s) a b
makeTransducer initialState stepTf onComplete next =
MkReducer (initialState, state next) stepImpl completeImpl
completeImpl (s', s) acc =
let acc = evalState (onComplete (runStep next) s' acc) s
in complete next s acc
stepImpl acc x = do
(s1', s1) <- get
let (result, s2) = runState (stepTf (runStep next) (s1', acc) x) s1
case result of
Done (s2', acc) => do
put (s2', s2)
pure (Done acc)
Continue (s2', acc) => do
put (s2', s2)
pure (Continue acc)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.