Skip to content

Instantly share code, notes, and snippets.

@tippenein
Created June 15, 2016 16:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tippenein/5d5c90b599f8ee5177c74762079c1bb0 to your computer and use it in GitHub Desktop.
Save tippenein/5d5c90b599f8ee5177c74762079c1bb0 to your computer and use it in GitHub Desktop.
λ: import Control.Lens
λ: :t _1
_1 :: (Functor f, Field1 s t a b) => (a -> f b) -> s -> f t
λ: :t _2
_2 :: (Functor f, Field2 s t a b) => (a -> f b) -> s -> f t
λ: :i Getting
type Getting r s a = (a -> Const r a) -> s -> Const r s
-- Defined in ‘Control.Lens.Getter’
λ: view _2 (1,2)
2
λ: view (_1 . _2) ((1,False),2)
False
λ: :i view
view ::
Control.Monad.Reader.Class.MonadReader s m => Getting a s a -> m a
-- Defined in ‘Control.Lens.Getter’
λ: :i over
over :: Profunctor p => Setting p s t a b -> p a b -> s -> t
-- Defined in ‘Control.Lens.Setter’
λ: :i _Right
_Right :: Prism (Either c a) (Either c b) a b
-- Defined in ‘Control.Lens.Prism’
λ: preview (_1 . _Right) (Right 'b', 123)
Just 'b'
λ: over (_1 . _Right) ord (Right 'a', 123)
λ: import Data.Char
λ: over (_1 . _Right) ord (Right 'a', 123)
(Right 97,123)
λ: over (_1 . _Right) ord (Left 42, 123)
(Left 42,123)
λ: :t contramap
contramap :: Contravariant f => (a -> b) -> f b -> f a
λ: :t contramap . map
contramap . map :: Contravariant f => (a -> b) -> f [b] -> f [a]
λ: :t contramap . fmap
contramap . fmap
:: (Functor f1, Contravariant f) =>
(a -> b) -> f (f1 b) -> f (f1 a)
λ: :t fmap . contramap
fmap . contramap
:: (Functor f, Contravariant f1) =>
(a -> b) -> f (f1 b) -> f (f1 a)
λ: import Data.Profunctor
λ: :t (Forget id)
(Forget id) :: Forget r r b
λ: :t ((first' . second) (Forget id))
λ: :t ((first' . second') (Forget id))
((first' . second') (Forget id))
:: Forget r ((c1, r), c) ((c1, b), c)
λ: import Control.Arrow
λ: :t (***)
(***) :: Arrow a => a b c -> a b' c' -> a (b, b') (c, c')
λ: ((+1) *** (+2)) (1,2)
(2,4)
λ: :t _Left
_Left
:: (Applicative f, Choice p) =>
p a (f b) -> p (Either a c) (f (Either b c))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment