This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
makeTransducer : | |
s' | |
-> (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 | |
where | |
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