Add Prelude/Bool/even
and Prelude/Bool/odd
This commit is contained in:
parent
63f5439f9d
commit
a58a4c7d86
21
Prelude/Bool/even
Normal file
21
Prelude/Bool/even
Normal 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
21
Prelude/Bool/odd
Normal 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
|
Loading…
Reference in New Issue
Block a user