Copyright | (c) 2016 Stephen Diehl (c) 2016-2018 Serokell (c) 2018-2020 Kowainik |
---|---|
License | MIT |
Maintainer | Kowainik <xrom.xkov@gmail.com> |
Stability | Stable |
Portability | Portable |
Safe Haskell | Safe |
Language | Haskell2010 |
One
is a typeclass for creating structures from a singleton element.
It has three main goals:
- Give a shorter name for the construction: uses
one
instead of commonsingleton
. - Work with monomorphic structures like
Text
orIntSet
. - Give a clearer and less scary name for cases where you can use
pure
or(:[])
.
Since: 0.1.0
Documentation
Typeclass for data types that can be created from one element.
>>>
one True :: [Bool]
[True]>>>
one 'a' :: Text
"a">>>
one (3, "hello") :: HashMap Int String
fromList [(3,"hello")]
Laws:
single-size
:∀ x . size (one x) ≡ 1
(where size
is a specific function for each container that returns the size of
this container)
Instances
One ShortByteString Source # | Create singleton
law> |
Defined in Relude.Container.One type OneItem ShortByteString :: Type Source # | |
One ByteString Source # | Create singleton lazy
law> |
Defined in Relude.Container.One type OneItem ByteString :: Type Source # one :: OneItem ByteString -> ByteString Source # | |
One ByteString Source # | Create singleton strict
law> |
Defined in Relude.Container.One type OneItem ByteString :: Type Source # one :: OneItem ByteString -> ByteString Source # | |
One IntSet Source # | Create singleton
law> |
One Text Source # | Create singleton lazy
law> |
One Text Source # | Create singleton strict
law> |
One [a] Source # | Allows to create a singleton list. You might prefer function with name
law> |
One (NonEmpty a) Source # | Allows to create singleton
law> |
One (IntMap v) Source # | Create singleton
law> |
One (Seq a) Source # | Create singleton
law> |
One (Set a) Source # | Create singleton
law> |
Hashable a => One (HashSet a) Source # | Create singleton
law> |
One (Map k v) Source # | Create singleton
law> |
Hashable k => One (HashMap k v) Source # | Create singleton
law> |