mirror of
https://github.com/idris-lang/Idris2.git
synced 2024-11-24 06:52:19 +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`.
|
* The `Data.List1` functions `foldr1` and `foldr1By` are now `public export`.
|
||||||
|
|
||||||
|
* Added `uncons' : List a -> Maybe (a, List a)` to `base`.
|
||||||
|
|
||||||
#### System
|
#### System
|
||||||
|
|
||||||
* Changes `getNProcessors` to return the number of online processors rather than
|
* Changes `getNProcessors` to return the number of online processors rather than
|
||||||
|
@ -561,17 +561,21 @@ init [] impossible
|
|||||||
init [x] = []
|
init [x] = []
|
||||||
init (x :: xs@(_::_)) = x :: init xs
|
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`.
|
||| Attempt to get the head of a list. If the list is empty, return `Nothing`.
|
||||||
public export
|
public export
|
||||||
head' : List a -> Maybe a
|
head' : List a -> Maybe a
|
||||||
head' [] = Nothing
|
head' = map fst . uncons'
|
||||||
head' (x::_) = Just x
|
|
||||||
|
|
||||||
||| Attempt to get the tail of a list. If the list is empty, return `Nothing`.
|
||| Attempt to get the tail of a list. If the list is empty, return `Nothing`.
|
||||||
export
|
export
|
||||||
tail' : List a -> Maybe (List a)
|
tail' : List a -> Maybe (List a)
|
||||||
tail' [] = Nothing
|
tail' = map snd . uncons'
|
||||||
tail' (_::xs) = Just xs
|
|
||||||
|
|
||||||
||| Attempt to retrieve the last element of a non-empty list.
|
||| Attempt to retrieve the last element of a non-empty list.
|
||||||
|||
|
|||
|
||||||
|
Loading…
Reference in New Issue
Block a user