mirror of
https://github.com/idris-lang/Idris2.git
synced 2024-09-11 13:36:08 +03:00
Add uncons' to base; rewrite head' and tail' in terms of uncons'
This commit is contained in:
parent
694b1650c8
commit
ebbae42c85
@ -191,6 +191,8 @@
|
||||
|
||||
* The `Data.List1` functions `foldr1` and `foldr1By` are now `public export`.
|
||||
|
||||
* Added `uncons' : List a -> Maybe (a, List a)` to `base`.
|
||||
|
||||
#### System
|
||||
|
||||
* Changes `getNProcessors` to return the number of online processors rather than
|
||||
|
@ -561,17 +561,21 @@ init [] impossible
|
||||
init [x] = []
|
||||
init (x :: xs@(_::_)) = x :: init xs
|
||||
|
||||
||| Attempt to deconstruct the list into a head and a tail.
|
||||
public export
|
||||
uncons' : List a -> Maybe (a, List a)
|
||||
uncons' [] = Nothing
|
||||
uncons' (x :: xs) = Just (x, xs)
|
||||
|
||||
||| Attempt to get the head of a list. If the list is empty, return `Nothing`.
|
||||
public export
|
||||
head' : List a -> Maybe a
|
||||
head' [] = Nothing
|
||||
head' (x::_) = Just x
|
||||
head' = map fst . uncons'
|
||||
|
||||
||| Attempt to get the tail of a list. If the list is empty, return `Nothing`.
|
||||
export
|
||||
tail' : List a -> Maybe (List a)
|
||||
tail' [] = Nothing
|
||||
tail' (_::xs) = Just xs
|
||||
tail' = map snd . uncons'
|
||||
|
||||
||| Attempt to retrieve the last element of a non-empty list.
|
||||
|||
|
||||
|
Loading…
Reference in New Issue
Block a user