Created
December 3, 2019 01:46
-
-
Save tonymorris/8391b6a7453d6be8914a98a8e2958268 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
{-# LANGUAGE RankNTypes #-} | |
{-# LANGUAGE LambdaCase #-} | |
import Control.Lens | |
import Data.Bool | |
import Data.Maybe | |
-- Control.Lens.Iso#anon | |
anon' :: | |
a | |
-> (a -> Bool) | |
-> Iso' (Maybe a) a | |
anon' a p = | |
iso | |
( | |
fromMaybe a | |
) | |
( | |
\a' -> | |
bool | |
(Just a') | |
Nothing | |
(p a') | |
) | |
anonR :: | |
x | |
-> (r -> Bool) | |
-> Iso (Either l x) (Either x r) x r | |
anonR a p = | |
iso | |
( | |
\case | |
Left _ -> | |
a | |
Right a' -> | |
a' | |
) | |
( | |
\a' -> | |
bool | |
(Right a') | |
(Left a) | |
(p a') | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment