diff options
| author | Hannes Schulze <contact@haschu.me> | 2026-06-05 23:36:58 +0200 |
|---|---|---|
| committer | Hannes Schulze <contact@haschu.me> | 2026-06-05 23:36:58 +0200 |
| commit | f4cff95f32c523ee794427d06740fe3eaca76421 (patch) | |
| tree | 80f3a631aba31c9b3de3409ed10c78548ceb5db8 /lib/Wayland/Basic/Lens.lean | |
| parent | 648edcd81fc2045cab70ec2b82d81577158d8613 (diff) | |
lens composition
Diffstat (limited to 'lib/Wayland/Basic/Lens.lean')
| -rw-r--r-- | lib/Wayland/Basic/Lens.lean | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/lib/Wayland/Basic/Lens.lean b/lib/Wayland/Basic/Lens.lean index 16de458..ee1e486 100644 --- a/lib/Wayland/Basic/Lens.lean +++ b/lib/Wayland/Basic/Lens.lean @@ -13,6 +13,16 @@ structure Lens (O I : Type) where /-- Update the outer structure to contain the updated substructure. -/ set : I → O → O +def Lens.id (X : Type) : Lens X X where + get x := x + set x _ := x + +def Lens.compose {X Y Z : Type} (l₁ : Lens X Y) (l₂ : Lens Y Z) : Lens X Z where + get := l₂.get ∘ l₁.get + set i o := l₁.set (l₂.set i (l₁.get o)) o + +scoped infixr:80 " ≫ " => Lens.compose + /-- Helper for writing a `Lens` constructor for a named field of a structure. -/ macro "mk_lens " field:ident : term => do let lvalNode := Lean.mkNode `Lean.Parser.Term.structInstLVal #[field.raw, Lean.mkNullNode #[]] |
