Created
November 11, 2015 07:12
-
-
Save dtchepak/d695a7ae8a7a1ff11162 to your computer and use it in GitHub Desktop.
Possible Elm lens, based on https://gist.github.com/evancz/78293dc6a4ac2547676c
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
-- Based on https://gist.github.com/evancz/78293dc6a4ac2547676c | |
type alias Lens s a = | |
{ get : s -> a | |
, set : a -> s -> s | |
} | |
modify : Lens s a -> (a -> a) -> s -> s | |
modify l f s = | |
l.set (f (l.get s)) s | |
assignTo : Lens s a -> s -> a -> s | |
assignTo l = flip l.set | |
(=>) : Lens s a -> Lens a b -> Lens s b | |
(=>) sa ab = | |
{ get s = ab.get (sa.get s) | |
, set b s = sa.set (ab.set b (sa.get s)) s | |
} | |
fst' : Lens (a,b) a | |
fst' = | |
{ get = fst | |
, set a (_,b) = (a,b) | |
} | |
snd' : Lens (a,b) b | |
snd' = | |
{ get = snd | |
, set b (a,_) = (a,b) | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment