Add optics for common types

This commit is contained in:
Kiana Sheibani 2023-04-17 13:27:33 -04:00
parent 5fdd7192b1
commit 783a1efe5e
Signed by: toki
GPG key ID: 6CB106C25E86A9F7
7 changed files with 174 additions and 0 deletions

View file

@ -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
View 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