Skip to content

Instantly share code, notes, and snippets.

@deque-blog
Created July 28, 2017 12:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save deque-blog/02b4a43d6eed78f882cb5cb9dc724ae5 to your computer and use it in GitHub Desktop.
Save deque-blog/02b4a43d6eed78f882cb5cb9dc724ae5 to your computer and use it in GitHub Desktop.
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