Created
August 23, 2015 03:14
-
-
Save TheSeamau5/c228c37f257802165f72 to your computer and use it in GitHub Desktop.
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
import Task exposing (Task) | |
type Never = Never Never | |
type Behavior a = Behavior (a -> Task Never (Behavior a)) | |
contramap : (b -> a) -> Behavior a -> Behavior b | |
contramap f (Behavior g) = | |
Behavior (\b -> Task.map (contramap f) (g (f b))) | |
divide : (c -> (a, b)) -> Behavior a -> Behavior b -> Behavior c | |
divide f (Behavior fa) (Behavior fb) = | |
Behavior <| | |
\c -> | |
case f c of | |
(a, b) -> | |
fa a | |
`Task.andThen` \behaviorA -> fb b | |
`Task.andThen` \behaviorB -> Task.succeed (divide f behaviorA behaviorB) | |
runBehavior : Behavior a -> List a -> Task Never () | |
runBehavior (Behavior f) list = | |
case list of | |
[] -> | |
Task.succeed () | |
x :: xs -> | |
f x | |
`Task.andThen` \behavior -> runBehavior behavior xs | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment