# ekmett/lens

2.9 final docs

1 parent 2601e53 commit 0761b92f9ee8851df4910f7d6b6feec196eaa204 committed Sep 13, 2012
13 Control-Lens-Iso.html
 @@ -11,9 +11,10 @@ from the Prelude or from Control.Category. However, if you compose them with each other using (.) from the Prelude, they will be dumbed down to a mere Lens. -

import Control.Category
- import Prelude hiding ((.),id)
-
type Iso a b c d = forall k f. (Isomorphic k, Functor f) => Overloaded k f a b c d

iso :: (Isomorphic k, Functor f) => (a -> b) -> (b -> a) -> k (b -> f b) (a -> f a)Source

Build a simple isomorphism from a pair of inverse functions +

+ import Control.Category
+ import Prelude hiding ((.),id)
+
type Iso a b c d = forall k f. (Isomorphic k, Functor f) => Overloaded k f a b c d

iso :: (Isomorphic k, Functor f) => (a -> b) -> (b -> a) -> k (b -> f b) (a -> f a)Source

Build a simple isomorphism from a pair of inverse functions

view (iso f g) ≡ f
view (from (iso f g)) ≡ g
@@ -31,9 +32,9 @@
10

auf :: Simple Iso a b -> ((d -> b) -> c -> b) -> (d -> a) -> c -> aSource

Based on ala' from Conor McBride's work on Epigram.

Mnemonically, the German auf plays a similar role to à la, and the combinator - is au with an extra function argument. + is ala with an extra function argument.

under :: Isomorphism (c -> Mutator d) (a -> Mutator b) -> (a -> b) -> c -> dSource

The opposite of working over a Setter is working under an Isomorphism. -

under = over . from
under :: Iso a b c d -> (a -> b) -> (c -> d)

Primitive isomorphisms +

under = over . from
under :: Iso a b c d -> (a -> b) -> c -> d

Primitive isomorphisms

from :: Isomorphic k => Isomorphism a b -> k b aSource

Invert an isomorphism.

Note to compose an isomorphism and receive an isomorphism in turn you'll need to use Category @@ -64,4 +65,4 @@

Storing Isomorphisms

newtype ReifiedIso a b c d Source

Useful for storing isomorphisms in containers.

Constructors

ReifyIso

Fields

reflectIso :: Iso a b c d

Simplicity -

type SimpleIso a b = Iso a a b bSource

type SimpleIso = Simple Iso

type SimpleReifiedIso a b = ReifiedIso a a b bSource

type SimpleReifiedIso = Simple ReifiedIso
+

type SimpleIso a b = Iso a a b bSource

10 Data-HashSet-Lens.html
 @@ -11,9 +11,9 @@

>>> setOf (folded._2) [("hello",1),("world",2),("!!!",3)]
fromList [1,2,3]
- setOf :: Hashable c         => Getter a c           -> a -> HashSet c
- setOf :: (Eq c, Hashable c) => Fold a c             -> a -> HashSet c
- setOf :: Hashable c         => Simple Iso a c       -> a -> HashSet c
- setOf :: Hashable c         => Simple Lens a c      -> a -> HashSet c
- setOf :: (Eq c, Hashable c) => Simple Traversal a c -> a -> HashSet c
+ setOf :: Hashable c         => Getter a c           -> a -> HashSet c
+ setOf :: (Eq c, Hashable c) => Fold a c             -> a -> HashSet c
+ setOf :: Hashable c         => Simple Iso a c       -> a -> HashSet c
+ setOf :: Hashable c         => Simple Lens a c      -> a -> HashSet c
+ setOf :: (Eq c, Hashable c) => Simple Traversal a c -> a -> HashSet c
12 Data-IntSet-Lens.html
 @@ -8,16 +8,16 @@ the elements to new values.

Sadly, you can't create a valid Traversal for a Set, because the number of elements might change but you can manipulate it by reading using folded and - reindexing it via setmap. + reindexing it via setmapped.

>>> over setmapped (+1) (fromList [1,2,3,4])
fromList [2,3,4,5]

setOf :: Getting IntSet a b Int d -> a -> IntSetSource

Construct an IntSet from a Getter, Fold, Traversal, Lens or Iso.

>>> setOf (folded._2) [("hello",1),("world",2),("!!!",3)]
fromList [1,2,3]
- setOf :: Getter a Int           -> a -> IntSet
- setOf :: Fold a Int             -> a -> IntSet
- setOf :: Simple Iso a Int       -> a -> IntSet
- setOf :: Simple Lens a Int      -> a -> IntSet
- setOf :: Simple Traversal a Int -> a -> IntSet
+ setOf :: Getter a Int           -> a -> IntSet
+ setOf :: Fold a Int             -> a -> IntSet
+ setOf :: Simple Iso a Int       -> a -> IntSet
+ setOf :: Simple Lens a Int      -> a -> IntSet
+ setOf :: Simple Traversal a Int -> a -> IntSet
12 Data-Set-Lens.html
 @@ -4,16 +4,16 @@

lens-2.9: Lenses, Folds and Traversals

Portabilityportable
Stabilityprovisional
MaintainerEdward Kmett <ekmett@gmail.com>

Data.Set.Lens

Description

Synopsis

Documentation

setmapped :: (Ord i, Ord j) => Setter (Set i) (Set j) i jSource

This Setter can be used to change the type of a Set by mapping the elements to new values.

Sadly, you can't create a valid Traversal for a Set, but you can - manipulate it by reading using folded and reindexing it via setmap. + manipulate it by reading using folded and reindexing it via setmapped.

>>> over setmapped (+1) (fromList [1,2,3,4])
fromList [2,3,4,5]

setOf :: Getting (Set c) a b c d -> a -> Set cSource

Construct a set from a Getter, Fold, Traversal, Lens or Iso.

>>> setOf (folded._2) [("hello",1),("world",2),("!!!",3)]
fromList [1,2,3]
- setOf ::          Getter a c           -> a -> Set c
- setOf :: Ord c => Fold a c             -> a -> Set c
- setOf ::          Simple Iso a c       -> a -> Set c
- setOf ::          Simple Lens a c      -> a -> Set c
- setOf :: Ord c => Simple Traversal a c -> a -> Set c
+ setOf ::          Getter a c           -> a -> Set c
+ setOf :: Ord c => Fold a c             -> a -> Set c
+ setOf ::          Simple Iso a c       -> a -> Set c
+ setOf ::          Simple Lens a c      -> a -> Set c
+ setOf :: Ord c => Simple Traversal a c -> a -> Set c
4 index.html
 @@ -26,7 +26,7 @@

Minimizing Dependencies

If you want to provide lenses and traversals for your own types in your own libraries, then you can do so without incurring a dependency on this (or any other) lens package at all. -

e.g. for a data type: +

e.g. for a data type:

data Foo a = Foo Int Int a

You can define lenses such as

-- bar :: Simple Lens (Foo a) Int
@@ -42,5 +42,5 @@
traverseBarAndBaz f (Foo a b c) = Foo <\$> f a <*> f b <*> pure c

What is provided in this library is a number of stock lenses and traversals for common haskell types, a wide array of combinators for working them, and more -exotic functionality, (e.g. getters, setters, indexed folds, isomorphisms). +exotic functionality, (e.g. getters, setters, indexed folds, isomorphisms).