Created
October 16, 2009 17:52
-
-
Save mattpodwysocki/211922 to your computer and use it in GitHub Desktop.
This file contains 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
module Event = | |
open System.Threading | |
let concat (source: IEvent<IEvent<_,_>>) = | |
let event = new Event<_>() | |
source.Add (Event.listen event.Trigger) | |
event.Publish | |
let collect f = | |
Event.map f >> concat | |
let post (context:SynchronizationContext) (sourceEvent: IEvent<IEvent<_,_>>) = | |
let event = new Event<_>() | |
sourceEvent.Add(fun args -> | |
context.Post(SendOrPostCallback(fun _ -> event.Trigger args), null)) | |
event.Publish | |
let sample interval (sourceEvent:IEvent<'del, 'a>) = | |
let event = new Event<_>() | |
let intervalCount = ref interval | |
sourceEvent.Add(fun args -> | |
if !intervalCount > 0 then decr intervalCount | |
else intervalCount := interval; event.Trigger args) | |
event.Publish | |
let skip n (sourceEvent:IEvent<_,_>) = | |
let event = new Event<_>() | |
let remaining = ref n | |
sourceEvent.Add(fun args -> if !remaining > 0 then decr remaining else event.Trigger args) | |
event.Publish | |
let skipWhile predicate (sourceEvent:IEvent<_,_>) = | |
let event = new Event<_>() | |
let ok = ref true | |
sourceEvent.Add(fun args -> | |
if !ok then | |
ok := predicate args | |
else | |
event.Trigger args) | |
event.Publish | |
let take n (sourceEvent:IEvent<_,_>) = | |
let event = new Event<_>() | |
let remaining = ref n | |
sourceEvent.Add(fun args -> if !remaining > 0 then decr remaining; event.Trigger args) | |
event.Publish | |
let takeWhile predicate (sourceEvent:IEvent<_,_>) = | |
let event = new Event<_>() | |
let ok = ref true | |
sourceEvent.Add(fun args -> | |
if !ok then | |
ok := predicate args | |
event.Trigger args) | |
event.Publish | |
let until (other: IEvent<_,_>) (source: IEvent<_,_>) = | |
let event = new Event<_>() | |
let ok = ref true | |
other .Add(fun _ -> ok := false) | |
source.Add(fun args -> if !ok then event.Trigger args) | |
event.Publish | |
let waitUntil (other: IEvent<_,_>) (source: IEvent<_,_>) = | |
let event = new Event<_>() | |
let ok = ref false | |
other .Add(fun _ -> ok := true) | |
source.Add(fun args -> if !ok then event.Trigger args) | |
event.Publish |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment