Define cons and snoc optics
This commit is contained in:
parent
de087603bf
commit
482edefd59
4 changed files with 81 additions and 1 deletions
|
|
@ -1,6 +1,7 @@
|
|||
module Control.Lens
|
||||
|
||||
import public Control.Lens.At
|
||||
import public Control.Lens.Cons
|
||||
import public Control.Lens.Equality
|
||||
import public Control.Lens.Fold
|
||||
import public Control.Lens.Getter
|
||||
|
|
|
|||
36
src/Control/Lens/Cons.idr
Normal file
36
src/Control/Lens/Cons.idr
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
module Control.Lens.Cons
|
||||
|
||||
import Data.Profunctor
|
||||
import Control.Lens.Optic
|
||||
import Control.Lens.Iso
|
||||
import Control.Lens.Prism
|
||||
import Control.Lens.Optional
|
||||
|
||||
%default total
|
||||
|
||||
|
||||
public export
|
||||
interface Cons s t a b | s where
|
||||
cons_ : Prism s t (a, s) (b, t)
|
||||
|
||||
public export
|
||||
head_ : Cons s s a a => Optional' s a
|
||||
head_ @{_} @{MkIsOptional _} = cons_ . first
|
||||
|
||||
public export
|
||||
tail_ : Cons s s a a => Optional' s s
|
||||
tail_ @{_} @{MkIsOptional _} = cons_ . second
|
||||
|
||||
|
||||
public export
|
||||
interface Snoc s t a b | s where
|
||||
snoc_ : Prism s t (s, a) (t, b)
|
||||
|
||||
public export
|
||||
init_ : Snoc s s a a => Optional' s s
|
||||
init_ @{_} @{MkIsOptional _} = snoc_ . first
|
||||
|
||||
public export
|
||||
last_ : Snoc s s a a => Optional' s a
|
||||
last_ @{_} @{MkIsOptional _} = snoc_ . second
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue