-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathbindOptional
More file actions
38 lines (30 loc) · 841 Bytes
/
bindOptional
File metadata and controls
38 lines (30 loc) · 841 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
{-
bindOptional binds to a `f` of Optional over the `f a` and `compact`s away the `None` values.
Examples:
```
let replicate =
https://raw.githubusercontent.com/dhall-lang/dhall-lang/master/Prelude/List/replicate
in ./Compactable/bindOptional
List
./List/compactable
./List/monad
Natural
Natural
( λ(n : Natural)
→ if Natural/even n
then replicate n (Optional Natural) (Some n)
else [] : List (Optional Natural)
)
[ 0, 1, 2, 3, 4, 5 ]
= [ 2, 2, 4, 4, 4, 4 ]
```
-}
let Monad = ./../Monad/Type
in λ(f : Type → Type)
→ λ(c : ./Type f)
→ λ(monad : Monad f)
→ λ(a : Type)
→ λ(b : Type)
→ λ(k : a → f (Optional b))
→ λ(fa : f a)
→ ./compact f c b (monad.bind a (Optional b) fa k)