summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOleg Grenrus <oleg.grenrus@iki.fi>2019-11-20 22:38:36 +0200
committerMarge Bot <ben+marge-bot@smart-cactus.org>2020-02-11 05:07:30 -0500
commit375b3c45be0e5de673d03097ebbad442c85c89eb (patch)
treef079d11bc1c935a4abf03b314c835e142dbb9a70
parent5670881d7779ecd7eee8c969dab66ee343298532 (diff)
downloadhaskell-375b3c45be0e5de673d03097ebbad442c85c89eb.tar.gz
Add singleton to Data.OldList
-rw-r--r--libraries/base/Data/OldList.hs11
1 files changed, 11 insertions, 0 deletions
diff --git a/libraries/base/Data/OldList.hs b/libraries/base/Data/OldList.hs
index ac5cbddb58..6110a4de31 100644
--- a/libraries/base/Data/OldList.hs
+++ b/libraries/base/Data/OldList.hs
@@ -26,6 +26,7 @@ module Data.OldList
, tail
, init
, uncons
+ , singleton
, null
, length
@@ -1269,6 +1270,16 @@ sortOn :: Ord b => (a -> b) -> [a] -> [a]
sortOn f =
map snd . sortBy (comparing fst) . map (\x -> let y = f x in y `seq` (y, x))
+-- | Produce singleton list.
+--
+-- >>> singleton True
+-- [True]
+--
+-- @since 4.14.0.0
+--
+singleton :: a -> [a]
+singleton x = [x]
+
-- | The 'unfoldr' function is a \`dual\' to 'foldr': while 'foldr'
-- reduces a list to a summary value, 'unfoldr' builds a list from
-- a seed value. The function takes the element and returns 'Nothing'