Skip to content

Instantly share code, notes, and snippets.

@hodzanassredin
Created September 30, 2012 21:07
Show Gist options
  • Save hodzanassredin/3808453 to your computer and use it in GitHub Desktop.
Save hodzanassredin/3808453 to your computer and use it in GitHub Desktop.
abstraction over pull and push sources
type 'a Source =
| Push of (('a Option -> Unit) -> Unit)
| Pull of (Unit -> 'a Option)
type 'a Destination =
| Destination of ('a Option -> Unit)
type Converter<'a,'b> =
| Converter of ('a Option -> 'b Option)
let combine conveter1 conveter2 =
match (conveter1, conveter2) with
| (Converter(a),Converter(b)) -> Converter(fun x -> b(a(x)))
let combine1 source conveter =
match (source, conveter) with
| (Push(a),Converter(b)) -> Push(fun f -> a(fun x -> f(b(x))))
| (Pull(a),Converter(b)) -> Pull(fun () -> b(a()))
let combine2 conveter destination =
match (conveter, destination) with
| (Converter(a),Destination(b)) -> Destination(fun v -> b(a(v)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment