| 1 | <h2>Full example</h2> |
| 2 | <pre><code> |
| 3 | -- source: https://github.com/dhall-lang/dhall-lang/blob/master/Prelude/Optional/head.dhall |
| 4 | |
| 5 | {- |
| 6 | Returns the first non-empty `Optional` value in a `List` |
| 7 | -} |
| 8 | let head |
| 9 | : ∀(a : Type) → List (Optional a) → Optional a |
| 10 | = λ(a : Type) → |
| 11 | λ(xs : List (Optional a)) → |
| 12 | List/fold |
| 13 | (Optional a) |
| 14 | xs |
| 15 | (Optional a) |
| 16 | ( λ(l : Optional a) → |
| 17 | λ(r : Optional a) → |
| 18 | merge { Some = λ(x : a) → Some x, None = r } l |
| 19 | ) |
| 20 | (None a) |
| 21 | |
| 22 | let example0 = assert : head Natural [ None Natural, Some 1, Some 2 ] ≡ Some 1 |
| 23 | |
| 24 | let example1 = |
| 25 | assert : head Natural [ None Natural, None Natural ] ≡ None Natural |
| 26 | |
| 27 | let example2 = |
| 28 | assert : head Natural ([] : List (Optional Natural)) ≡ None Natural |
| 29 | |
| 30 | in head</code></pre> |