Created
September 30, 2012 21:07
-
-
Save hodzanassredin/3808453 to your computer and use it in GitHub Desktop.
abstraction over pull and push sources
This file contains hidden or 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
| 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