Last active
August 29, 2015 14:27
-
-
Save TheSeamau5/b70413c3230121fd7ac1 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, succeed) | |
type Never = Never Never | |
type alias Address e = e -> Task Never () | |
forwardTo : Address a -> (b -> a) -> Address b | |
forwardTo address f b = | |
address (f b) | |
type alias Loopback a b = Address a -> Address b | |
map : (a -> b) -> Loopback a x -> Loopback b x | |
map f loopA address x = | |
loopA (forwardTo address f) x | |
reroute : (b -> Maybe a) -> Loopback x a -> Loopback x b | |
reroute f loopA address b = | |
case f b of | |
Nothing -> | |
succeed () | |
Just a -> | |
loopA address a | |
dimap : (a -> b) -> (d -> Maybe c) -> Loopback a c -> Loopback b d | |
dimap f g = | |
map f >> reroute g | |
type ListAction a | |
= ChildAction Int a | |
list : Loopback action effect -> Loopback (ListAction action) (ListAction effect) | |
list loopback address (ChildAction n effect) = | |
loopback (forwardTo address (ChildAction n)) effect | |
type Json | |
= String String | |
| Int Int | |
| Float Float | |
| List (List Json) | |
| Object String Json | |
getInt : Json -> Maybe Int | |
getInt json = | |
case json of | |
Int n -> Just n | |
_ -> Nothing | |
int : Loopback Int Int -> Loopback Json Json | |
int = | |
dimap Int getInt | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment