Skip to content
Snippets Groups Projects
Commit a214d214 authored by muesli4's avatar muesli4 Committed by Marge Bot
Browse files

Add singleton to NonEmpty in libraries/base

This adds a definition to construct a singleton non-empty list
(Data.List.NonEmpty) according to issue #17851.
parent 9462452a
No related branches found
No related tags found
No related merge requests found
......@@ -42,6 +42,7 @@ module Data.List.NonEmpty (
, tail -- :: NonEmpty a -> [a]
, last -- :: NonEmpty a -> a
, init -- :: NonEmpty a -> [a]
, singleton -- :: a -> NonEmpty a
, (<|), cons -- :: a -> NonEmpty a -> NonEmpty a
, uncons -- :: NonEmpty a -> (a, Maybe (NonEmpty a))
, unfoldr -- :: (a -> (b, Maybe a)) -> a -> NonEmpty b
......@@ -168,6 +169,12 @@ last ~(a :| as) = List.last (a : as)
init :: NonEmpty a -> [a]
init ~(a :| as) = List.init (a : as)
-- | Construct a 'NonEmpty' list from a single element.
--
-- @since 4.15
singleton :: a -> NonEmpty a
singleton a = a :| []
-- | Prepend an element to the stream.
(<|) :: a -> NonEmpty a -> NonEmpty a
a <| ~(b :| bs) = a :| b : bs
......
......@@ -9,6 +9,9 @@
* Add `hGetContents'`, `getContents'`, and `readFile'` in `System.IO`:
Strict IO variants of `hGetContents`, `getContents`, and `readFile`.
* Add `singleton` function for `Data.List.NonEmpty`.
## 4.14.0.0 *TBA*
* Bundled with GHC 8.10.1
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment