Skip to content

Instantly share code, notes, and snippets.

@zindel
Last active November 2, 2018 16:55
Show Gist options
  • Select an option

  • Save zindel/067c9010c24c355216b08aedb2a9c540 to your computer and use it in GitHub Desktop.

Select an option

Save zindel/067c9010c24c355216b08aedb2a9c540 to your computer and use it in GitHub Desktop.
module Action = {
type t('i, 'o) = 'i => 'o;
let chain = (action1, action2, arg) => arg |> action1 |> action2;
};
module Rule = {
type t('i, 'o) = {
action: Action.t('i, 'o),
f: option(unit),
};
let make = action => {action, f: None};
let chain = ({action: a1, _}, {action: a2, _}) => {
action: Action.chain(a1, a2),
f: None,
};
let execute = (input, {action, _}) => action(input);
};
let test = () => {
let hello = Rule.make(() => "Hello");
let plusWorld = Rule.make(s => s ++ ", world");
let print = Rule.make(print_endline);
let all = Rule.(chain(chain(hello, plusWorld), print));
Rule.execute((), all);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment