Skip to content

Commit

Permalink
feat(StateT): Add State eval functions
Browse files Browse the repository at this point in the history
  • Loading branch information
amsross committed May 4, 2020
1 parent 9377433 commit fb2b65a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/Transformers.re
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,13 @@ module StateT = (T: Interface.TYPE, M: Interface.MONAD) => {
let s' = f(s);
M.pure((s', s'));
};

let runWith: (T.t, t('a)) => m(('a, T.t)) =
(e, s) => s(e) |> M.map(((a, s)) => (s, a));
let evalWith: (T.t, t('a)) => m('a) =
(e, s) => runWith(e, s) |> M.map(fst);
let execWith: (T.t, t('a)) => m(T.t) =
(e, s) => runWith(e, s) |> M.map(snd);
};

module ReaderT = (T: Interface.TYPE, M: Interface.MONAD) => {
Expand Down
4 changes: 4 additions & 0 deletions src/Transformers.rei
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ module StateT:
let get: t(T.t);
let put: T.t => t(unit);
let modify: (T.t => T.t) => t(T.t);

let runWith: (T.t, t('a)) => m(('a, T.t));
let evalWith: (T.t, t('a)) => m('a);
let execWith: (T.t, t('a)) => m(T.t);
};

module ReaderT:
Expand Down

0 comments on commit fb2b65a

Please sign in to comment.