Skip to content

Instantly share code, notes, and snippets.

@tonymorris
Created December 3, 2019 01:46
Show Gist options
  • Save tonymorris/8391b6a7453d6be8914a98a8e2958268 to your computer and use it in GitHub Desktop.
Save tonymorris/8391b6a7453d6be8914a98a8e2958268 to your computer and use it in GitHub Desktop.
{-# 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