36 lines
939 B
Text
36 lines
939 B
Text
λ(nix : ../NixPrelude.dhall) →
|
|
let Any = ../Any/Type.dhall
|
|
|
|
let Any/toTypeUnchecked = ../Any/toTypeUnchecked.dhall nix
|
|
|
|
let Any/equal = ../Any/equal.dhall nix
|
|
|
|
let Any/toAny = ../Any/toAny.dhall nix
|
|
|
|
let null = Any/toAny (Optional Any) (None Any)
|
|
|
|
let isNone =
|
|
λ(t : Type) →
|
|
λ(o : Optional t) →
|
|
Any/equal (Any/toAny (Optional t) o) null
|
|
|
|
let unwrapUnsafe =
|
|
λ(t : Type) →
|
|
λ(o : Optional t) →
|
|
Any/toTypeUnchecked t (Any/toAny (Optional t) o)
|
|
|
|
let fold
|
|
: ∀(a : Type) →
|
|
Optional a →
|
|
∀(optional : Type) →
|
|
∀(some : a → optional) →
|
|
∀(none : optional) →
|
|
optional
|
|
= λ(a : Type) →
|
|
λ(o : Optional a) →
|
|
λ(optional : Type) →
|
|
λ(some : a → optional) →
|
|
λ(none : optional) →
|
|
if isNone a o then none else some (unwrapUnsafe a o)
|
|
|
|
in fold
|