Created
April 26, 2015 13:55
-
-
Save SteveGilham/b6e396281da0a4c94b9f to your computer and use it in GitHub Desktop.
Async monad
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
let ReturnAsync x = async { return x } | |
let (>>=!) m f = async { return Async.RunSynchronously(f(Async.RunSynchronously m)) } | |
let (>>!) m1 m2 = m1 >>=! fun () -> m2 | |
let (>=>!) f g = fun x -> ((f x) >>=! g) | |
let ApplyAsync m1 m2 = | |
m1 >>=! fun f -> | |
m2 >>=! fun x -> | |
ReturnAsync (f x) | |
let LiftAsync f = ApplyAsync (ReturnAsync f) | |
let SequenceAsync (l : _ list) = | |
Async.Parallel l >>=! fun a -> | |
ReturnAsync(Array.toList a);; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment