add Optional/
This commit is contained in:
parent
8fc7b60c0e
commit
ff0991ea10
13 changed files with 160 additions and 0 deletions
5
Optional/all.dhall
Normal file
5
Optional/all.dhall
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
λ(nix : ../NixPrelude.dhall) →
|
||||||
|
λ(a : Type) →
|
||||||
|
λ(f : a → Bool) →
|
||||||
|
λ(xs : Optional a) →
|
||||||
|
let fold = ./fold.dhall nix in fold a xs Bool f True
|
5
Optional/any.dhall
Normal file
5
Optional/any.dhall
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
λ(nix : ../NixPrelude.dhall) →
|
||||||
|
λ(a : Type) →
|
||||||
|
λ(f : a → Bool) →
|
||||||
|
λ(xs : Optional a) →
|
||||||
|
let fold = ./fold.dhall nix in fold a xs Bool f False
|
41
Optional/build.dhall
Normal file
41
Optional/build.dhall
Normal file
|
@ -0,0 +1,41 @@
|
||||||
|
--| `build` is the inverse of `fold`
|
||||||
|
let build
|
||||||
|
: ∀(a : Type) →
|
||||||
|
( ∀(optional : Type) →
|
||||||
|
∀(some : a → optional) →
|
||||||
|
∀(none : optional) →
|
||||||
|
optional
|
||||||
|
) →
|
||||||
|
Optional a
|
||||||
|
= λ(a : Type) →
|
||||||
|
λ ( build
|
||||||
|
: ∀(optional : Type) →
|
||||||
|
∀(some : a → optional) →
|
||||||
|
∀(none : optional) →
|
||||||
|
optional
|
||||||
|
) →
|
||||||
|
build (Optional a) (λ(x : a) → Some x) (None a)
|
||||||
|
|
||||||
|
let example0 =
|
||||||
|
assert
|
||||||
|
: build
|
||||||
|
Natural
|
||||||
|
( λ(optional : Type) →
|
||||||
|
λ(some : Natural → optional) →
|
||||||
|
λ(none : optional) →
|
||||||
|
some 1
|
||||||
|
)
|
||||||
|
≡ Some 1
|
||||||
|
|
||||||
|
let example1 =
|
||||||
|
assert
|
||||||
|
: build
|
||||||
|
Natural
|
||||||
|
( λ(optional : Type) →
|
||||||
|
λ(some : Natural → optional) →
|
||||||
|
λ(none : optional) →
|
||||||
|
none
|
||||||
|
)
|
||||||
|
≡ None Natural
|
||||||
|
|
||||||
|
in build
|
8
Optional/concat.dhall
Normal file
8
Optional/concat.dhall
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
λ(nix : ../NixPrelude.dhall) →
|
||||||
|
λ(a : Type) →
|
||||||
|
λ(x : Optional (Optional a)) →
|
||||||
|
let identity = ../Function/identity.dhall
|
||||||
|
|
||||||
|
let fold = ./fold.dhall nix
|
||||||
|
|
||||||
|
in fold (Optional a) x (Optional a) (identity (Optional a)) (None a)
|
10
Optional/concatMap.dhall
Normal file
10
Optional/concatMap.dhall
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
λ(nix : ../NixPrelude.dhall) →
|
||||||
|
λ(a : Type) →
|
||||||
|
λ(b : Type) →
|
||||||
|
λ(f : a → Optional b) →
|
||||||
|
λ(o : Optional a) →
|
||||||
|
let map = ./map.dhall nix
|
||||||
|
|
||||||
|
let concat = ./concat.dhall nix
|
||||||
|
|
||||||
|
in concat b (map a (Optional b) f o)
|
7
Optional/filter.dhall
Normal file
7
Optional/filter.dhall
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
λ(nix : ../NixPrelude.dhall) →
|
||||||
|
λ(a : Type) →
|
||||||
|
λ(f : a → Bool) →
|
||||||
|
λ(xs : Optional a) →
|
||||||
|
let concatMap = ./concatMap.dhall nix
|
||||||
|
|
||||||
|
in concatMap a a (λ(v : a) → if f v then Some v else None a) xs
|
18
Optional/head.dhall
Normal file
18
Optional/head.dhall
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
λ(nix : ../NixPrelude.dhall) →
|
||||||
|
let fold = ./fold.dhall nix
|
||||||
|
|
||||||
|
let head
|
||||||
|
: ∀(a : Type) → List (Optional a) → Optional a
|
||||||
|
= λ(a : Type) →
|
||||||
|
λ(xs : List (Optional a)) →
|
||||||
|
List/fold
|
||||||
|
(Optional a)
|
||||||
|
xs
|
||||||
|
(Optional a)
|
||||||
|
( λ(l : Optional a) →
|
||||||
|
λ(r : Optional a) →
|
||||||
|
fold a l (Optional a) (λ(v : a) → Some v) r
|
||||||
|
)
|
||||||
|
(None a)
|
||||||
|
|
||||||
|
in head
|
18
Optional/last.dhall
Normal file
18
Optional/last.dhall
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
λ(nix : ../NixPrelude.dhall) →
|
||||||
|
let fold = ./fold.dhall nix
|
||||||
|
|
||||||
|
let head
|
||||||
|
: ∀(a : Type) → List (Optional a) → Optional a
|
||||||
|
= λ(a : Type) →
|
||||||
|
λ(xs : List (Optional a)) →
|
||||||
|
List/fold
|
||||||
|
(Optional a)
|
||||||
|
xs
|
||||||
|
(Optional a)
|
||||||
|
( λ(l : Optional a) →
|
||||||
|
λ(r : Optional a) →
|
||||||
|
fold a r (Optional a) (λ(v : a) → Some v) l
|
||||||
|
)
|
||||||
|
(None a)
|
||||||
|
|
||||||
|
in head
|
8
Optional/length.dhall
Normal file
8
Optional/length.dhall
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
λ(nix : ../NixPrelude.dhall) →
|
||||||
|
let fold = ./fold.dhall nix
|
||||||
|
|
||||||
|
let length
|
||||||
|
: ∀(a : Type) → Optional a → Natural
|
||||||
|
= λ(a : Type) → λ(xs : Optional a) → fold a xs Natural (λ(_ : a) → 1) 0
|
||||||
|
|
||||||
|
in length
|
10
Optional/null.dhall
Normal file
10
Optional/null.dhall
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
λ(nix : ../NixPrelude.dhall) →
|
||||||
|
let fold = ./fold.dhall nix
|
||||||
|
|
||||||
|
let null
|
||||||
|
: ∀(a : Type) → Optional a → Bool
|
||||||
|
= λ(a : Type) →
|
||||||
|
λ(xs : Optional a) →
|
||||||
|
fold a xs Bool (λ(_ : a) → True) False
|
||||||
|
|
||||||
|
in null
|
17
Optional/package.dhall
Normal file
17
Optional/package.dhall
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
λ(nix : ../NixPrelude.dhall) →
|
||||||
|
{ all = ./all.dhall nix
|
||||||
|
, any = ./any.dhall nix
|
||||||
|
, build = ./build.dhall
|
||||||
|
, concat = ./concat.dhall nix
|
||||||
|
, concatMap = ./concatMap.dhall nix
|
||||||
|
, default = ./default.dhall nix
|
||||||
|
, filter = ./filter.dhall nix
|
||||||
|
, fold = ./fold.dhall nix
|
||||||
|
, head = ./head.dhall nix
|
||||||
|
, last = ./last.dhall nix
|
||||||
|
, length = ./length.dhall nix
|
||||||
|
, map = ./map.dhall nix
|
||||||
|
, null = ./null.dhall nix
|
||||||
|
, toList = ./toList.dhall nix
|
||||||
|
, unzip = ./unzip.dhall nix
|
||||||
|
}
|
12
Optional/unzip.dhall
Normal file
12
Optional/unzip.dhall
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
λ(nix : ../NixPrelude.dhall) →
|
||||||
|
let fold = ./fold.dhall nix
|
||||||
|
|
||||||
|
in λ(a : Type) →
|
||||||
|
λ(b : Type) →
|
||||||
|
λ(xs : Optional { _1 : a, _2 : b }) →
|
||||||
|
fold
|
||||||
|
{ _1 : a, _2 : b }
|
||||||
|
xs
|
||||||
|
{ _1 : Optional a, _2 : Optional b }
|
||||||
|
(λ(v : { _1 : a, _2 : b }) → { _1 = Some v._1, _2 = Some v._2 })
|
||||||
|
{ _1 = None a, _2 = None b }
|
|
@ -12,6 +12,7 @@
|
||||||
, NonNull = ./NonEmpty/package.dhall nix
|
, NonNull = ./NonEmpty/package.dhall nix
|
||||||
, Natural = ./Natural/package.dhall nix
|
, Natural = ./Natural/package.dhall nix
|
||||||
, Number = ./Number/package.dhall nix
|
, Number = ./Number/package.dhall nix
|
||||||
|
, Optional = ./Optional/package.dhall nix
|
||||||
, Path = ./Path/package.dhall nix
|
, Path = ./Path/package.dhall nix
|
||||||
, Set = ./Set/package.dhall nix
|
, Set = ./Set/package.dhall nix
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue