Portability | portable |
---|---|
Stability | provisional |
Maintainer | Edward Kmett <ekmett@gmail.com> |
Safe Haskell | None |
A self-contained lens library with lenses that are compatible with other van Laarhoven lens libraries.
Lenses produced by this library are compatible with other van Laarhoven lens family libraries, such as lens-family, lens-family-core and lens-family-th, but the API is simpler.
Note: If you merely want your library to provide lenses you may not have to actually import _any_ lens library, for a Lens Bar Foo, just export a function with the signature:
foo :: Functor f => (Foo -> f Foo) -> Bar -> f Bar
and then you can compose it with other lenses using (.).
- type Lens a b = forall f. Functor f => (b -> f b) -> a -> f a
- type LensFamily a b c d = forall f. Functor f => (c -> f d) -> a -> f b
- makeLenses :: Name -> Q [Dec]
- makeLensesBy :: (String -> Maybe String) -> Name -> Q [Dec]
- makeLensesFor :: [(String, String)] -> Name -> Q [Dec]
- lens :: Functor f => (a -> c) -> (d -> a -> b) -> (c -> f d) -> a -> f b
- iso :: Functor f => (a -> c) -> (d -> b) -> (c -> f d) -> a -> f b
- clone :: Functor f => ((c -> IndexedStore c d d) -> a -> IndexedStore c d b) -> (c -> f d) -> a -> f b
- getL :: ((c -> Const c d) -> a -> Const c b) -> a -> c
- modL :: ((c -> Identity d) -> a -> Identity b) -> (c -> d) -> a -> b
- setL :: ((c -> Identity d) -> a -> Identity b) -> d -> a -> b
- (^.) :: a -> ((c -> Const c d) -> a -> Const c b) -> c
- (^$) :: ((c -> Const c d) -> a -> Const c b) -> a -> c
- (^%=) :: ((c -> Identity d) -> a -> Identity b) -> (c -> d) -> a -> b
- (^=) :: ((c -> Identity d) -> a -> Identity b) -> d -> a -> b
- (^+=) :: Num c => ((c -> Identity c) -> a -> Identity a) -> c -> a -> a
- (^-=) :: Num c => ((c -> Identity c) -> a -> Identity a) -> c -> a -> a
- (^*=) :: Num c => ((c -> Identity c) -> a -> Identity a) -> c -> a -> a
- (^/=) :: Fractional c => ((c -> Identity c) -> a -> Identity a) -> c -> a -> a
- (^||=) :: ((Bool -> Identity Bool) -> a -> Identity a) -> Bool -> a -> a
- (^&&=) :: ((Bool -> Identity Bool) -> a -> Identity a) -> Bool -> a -> a
- access :: MonadState a m => ((c -> Const c d) -> a -> Const c b) -> m c
- class Focus st where
- (%=) :: MonadState a m => Setter a b -> (b -> b) -> m ()
- (~=) :: MonadState a m => Setter a b -> b -> m ()
- (%%=) :: MonadState a m => ((b -> (c, b)) -> a -> (c, a)) -> (b -> (c, b)) -> m c
- (+=) :: (MonadState a m, Num b) => Setter a b -> b -> m ()
- (-=) :: (MonadState a m, Num b) => Setter a b -> b -> m ()
- (*=) :: (MonadState a m, Num b) => Setter a b -> b -> m ()
- (//=) :: (MonadState a m, Fractional b) => Setter a b -> b -> m ()
- (||=) :: MonadState a m => Setter a Bool -> Bool -> m ()
- (&&=) :: MonadState a m => Setter a Bool -> Bool -> m ()
- fstLens :: LensFamily (a, c) (b, c) a b
- sndLens :: LensFamily (c, a) (c, b) a b
- mapLens :: Ord k => k -> Lens (Map k v) (Maybe v)
- intMapLens :: Int -> Lens (IntMap v) (Maybe v)
- setLens :: Ord k => k -> Lens (Set k) Bool
- intSetLens :: Int -> Lens IntSet Bool
- type Getter a b = forall x y z. (b -> Const z x) -> a -> Const z y
- getting :: (a -> c) -> (c -> Const r d) -> a -> Const r b
- type Setter a b = (b -> Identity b) -> a -> Identity a
- type SetterFamily a b c d = (c -> Identity d) -> a -> Identity b
- setting :: ((c -> d) -> a -> b) -> (c -> Identity d) -> a -> Identity b
- data IndexedStore c d a = IndexedStore (d -> a) c
- newtype Focusing m c a = Focusing {
- unfocusing :: m (c, a)
Lenses
type LensFamily a b c d = forall f. Functor f => (c -> f d) -> a -> f bSource
Constructing lenses
makeLenses :: Name -> Q [Dec]Source
Derive lenses for the record selectors in a single-constructor data declaration, or for the record selector in a newtype declaration. Lenses will only be generated for record fields which are prefixed with an underscore.
Example usage:
makeLenses ''Foo
Derive lenses with the provided name transformation
and filtering function. Produce Just lensName
to generate a lens
of the resultant name, or Nothing
to not generate a lens
for the input record name.
Example usage:
makeLensesBy (\n -> Just (n ++ "L")) ''Foo
makeLensesFor :: [(String, String)] -> Name -> Q [Dec]Source
Derive lenses, specifying explicit pairings of (fieldName, lensName)
.
Example usage:
makeLensesFor [("_foo", "fooLens"), ("bar", "lbar")] ''Foo
clone :: Functor f => ((c -> IndexedStore c d d) -> a -> IndexedStore c d b) -> (c -> f d) -> a -> f bSource
Reading from lenses
(^/=) :: Fractional c => ((c -> Identity c) -> a -> Identity a) -> c -> a -> aSource
Manipulating state
access :: MonadState a m => ((c -> Const c d) -> a -> Const c b) -> m cSource
(%=) :: MonadState a m => Setter a b -> (b -> b) -> m ()Source
(~=) :: MonadState a m => Setter a b -> b -> m ()Source
(%%=) :: MonadState a m => ((b -> (c, b)) -> a -> (c, a)) -> (b -> (c, b)) -> m cSource
(//=) :: (MonadState a m, Fractional b) => Setter a b -> b -> m ()Source
Common lenses
fstLens :: LensFamily (a, c) (b, c) a bSource
sndLens :: LensFamily (c, a) (c, b) a bSource
Getters
Setters
type SetterFamily a b c d = (c -> Identity d) -> a -> Identity bSource