[Git][ghc/ghc][master] Add singleton to NonEmpty in libraries/base
Marge Bot
gitlab at gitlab.haskell.org
Fri Apr 3 10:26:21 UTC 2020
Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC
Commits:
a214d214 by Moritz Bruder at 2020-04-03T06:26:11-04:00
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.
- - - - -
2 changed files:
- libraries/base/Data/List/NonEmpty.hs
- libraries/base/changelog.md
Changes:
=====================================
libraries/base/Data/List/NonEmpty.hs
=====================================
@@ -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
=====================================
libraries/base/changelog.md
=====================================
@@ -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
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/a214d2142c1bafa71fe52cb3823351ff9322d336
--
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/a214d2142c1bafa71fe52cb3823351ff9322d336
You're receiving this email because of your account on gitlab.haskell.org.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/ghc-commits/attachments/20200403/81855676/attachment-0001.html>
More information about the ghc-commits
mailing list