Add Prelude/Bool/even and Prelude/Bool/odd

This commit is contained in:
Gabriel Gonzalez 2016-12-03 19:17:25 -08:00
parent 63f5439f9d
commit a58a4c7d86
2 changed files with 42 additions and 0 deletions

21
Prelude/Bool/even Normal file
View File

@ -0,0 +1,21 @@
{-
Returns `True` if there are an even number of `False` elements in the list and
returns `False` otherwise
Examples:
```
./even ([False, True, False] : List Bool) = True
./even ([False, True] : List Bool) = False
./even ([False] : List Bool) = False
./even ([] : List Bool) = True
```
-}
let even : List Bool → Bool
= λ(xs : List Bool)
→ List/fold Bool xs Bool (λ(x : Bool) → λ(y : Bool) → x == y) True
in even

21
Prelude/Bool/odd Normal file
View File

@ -0,0 +1,21 @@
{-
Returns `True` if there are an odd number of `True` elements in the list and
returns `False` otherwise
Examples:
```
./odd ([True, False, True] : List Bool) = False
./odd ([True, False] : List Bool) = True
./odd ([True] : List Bool) = True
./odd ([] : List Bool) = False
```
-}
let odd : List Bool → Bool
= λ(xs : List Bool)
→ List/fold Bool xs Bool (λ(x : Bool) → λ(y : Bool) → x != y) False
in odd