Skip to content

Instantly share code, notes, and snippets.

@SteveGilham
Created April 26, 2015 13:55
Show Gist options
  • Save SteveGilham/b6e396281da0a4c94b9f to your computer and use it in GitHub Desktop.
Save SteveGilham/b6e396281da0a4c94b9f to your computer and use it in GitHub Desktop.
Async monad
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