-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Easily and clearly create lists with only one element in them. -- -- The list-singleton package allows you to easily and clearly -- create lists with only one element in them, which are typically called -- "singleton lists" or simply "singletons". (Not to be confused with the -- singletons package!) -- -- With any luck this library will be included in future versions of the -- base package. See this mailing list thread for an -- extended discussion: -- https://mail.haskell.org/pipermail/libraries/2019-August/029801.html. @package list-singleton @version 1.0.0.3 -- | This module is meant to augment the Data.List.NonEmpty module. -- You may want to import both modules using the same alias. For example: -- --
-- import qualified Data.List.NonEmpty as NonEmpty -- import qualified Data.List.NonEmpty.Singleton as NonEmpty --module Data.List.NonEmpty.Singleton -- | O(1) Create a non-empty list with a single element in it. -- --
-- >>> singleton "pepperoni" -- "pepperoni" :| [] ---- -- If you want to create a regular list with a single element in it, -- consider using singleton from Data.List.Singleton. singleton :: a -> NonEmpty a -- | This module is meant to augment the Data.List module. You may -- want to import both modules using the same alias. For example: -- --
-- import qualified Data.List as List -- import qualified Data.List.Singleton as List --module Data.List.Singleton -- | O(1) Create a list with a single element in it. -- --
-- >>> singleton "pepperoni" -- ["pepperoni"] ---- -- There are many other ways to construct lists, so why might you prefer -- to use singleton? Here's a comparison with a few popular -- methods: -- --
-- Instead of this: -- singleton x -- Consider this instead: [x]
-- -- Instead of this: g . (\ x -> [x]) . f -- Consider this instead: g . -- singleton . f
-- Instead of this: g . (: []) . f -- -- Consider this instead: g . singleton . f
>>> import Data.Char (chr) >>> print (pure -- (chr 72)) ... <interactive>:2:8: error: * Ambiguous type -- variable `f0' arising from a use of `pure' prevents the constraint -- `(Applicative f0)' from being solved. Probable fix: use a type -- annotation to specify what `f0' should be. ... >>> print -- (singleton (chr 72)) "H"
-- Instead of this: g . -- pure . f -- Consider this instead: g . singleton . f --
-- >>> import qualified Data.List.Singleton as List -- -- >>> import qualified Data.Set as Set -- -- >>> let aList = [2, 1, 3, 1] -- -- >>> foldMap Set.singleton aList -- fromList [1, 2, 3] -- -- >>> let aSet = Set.fromList [2, 3, 1] -- -- >>> foldMap List.singleton aSet -- [1, 2, 3] ---- -- The name "singleton" was chosen to mirror similar functions provided -- by other libraries. For example: -- --
-- >>> length (singleton undefined) -- 1 ---- -- If you want to create a NonEmpty list with a single element in -- it, consider using singleton from -- Data.List.NonEmpty.Singleton. singleton :: a -> [a]