Add optics for common types
This commit is contained in:
parent
5fdd7192b1
commit
783a1efe5e
7 changed files with 174 additions and 0 deletions
|
|
@ -1,5 +1,6 @@
|
|||
module Control.Lens
|
||||
|
||||
import public Control.Lens.At
|
||||
import public Control.Lens.Equality
|
||||
import public Control.Lens.Fold
|
||||
import public Control.Lens.Getter
|
||||
|
|
|
|||
36
src/Control/Lens/At.idr
Normal file
36
src/Control/Lens/At.idr
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
module Control.Lens.At
|
||||
|
||||
import Control.Lens.Optic
|
||||
import Control.Lens.Lens
|
||||
import Control.Lens.Optional
|
||||
import Control.Lens.Traversal
|
||||
import Control.Lens.Setter
|
||||
|
||||
%default total
|
||||
|
||||
|
||||
public export
|
||||
interface Ixed i v a | a where
|
||||
ix : i -> Optional' a v
|
||||
|
||||
public export
|
||||
[Function] Eq e => Ixed e a (e -> a) where
|
||||
ix k = optional' (Just . ($ k)) (\f,x,k' => if k == k' then x else f k')
|
||||
|
||||
|
||||
public export
|
||||
interface Ixed i v a => Ixed' i i' v a | a where
|
||||
ix' : i' -> Lens' a v
|
||||
|
||||
public export
|
||||
[Function'] Eq e => Ixed' e e a (e -> a) using Function where
|
||||
ix' k = lens ($ k) (\f,x,k' => if k == k' then x else f k')
|
||||
|
||||
|
||||
public export
|
||||
interface Ixed i v a => At i v a | a where
|
||||
at : i -> Lens' a (Maybe v)
|
||||
|
||||
public export
|
||||
sans : At i v a => i -> a -> a
|
||||
sans k = at k .~ Nothing
|
||||
Loading…
Add table
Add a link
Reference in a new issue