Copyright | (c) 2016 Stephen Diehl (c) 2016-2018 Serokell (c) 2018-2023 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. E.g. lists, non-empty containers, maps.
>>>
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 ByteString Source # | Create singleton strict
law> | ||||
Defined in Relude.Container.One
one :: OneItem ByteString -> ByteString Source # | |||||
One ByteString Source # | Create singleton lazy
law> | ||||
Defined in Relude.Container.One
one :: OneItem ByteString -> ByteString Source # | |||||
One ShortByteString Source # | Create singleton
law> | ||||
Defined in Relude.Container.One
| |||||
One IntSet Source # | Create singleton
law> | ||||
One Text Source # | Create singleton strict
law> | ||||
One Text Source # | Create singleton lazy
law> | ||||
One (IntMap v) Source # | Create singleton
law> | ||||
One (Seq a) Source # | Create singleton
law> | ||||
One (Set a) Source # | Create singleton
law> | ||||
One (NonEmpty a) Source # | Allows to create singleton
law> | ||||
Hashable a => One (HashSet a) Source # | Create singleton
law> | ||||
One [a] Source # | Allows to create a singleton list. You might prefer function with name
law> | ||||
Defined in Relude.Container.One
| |||||
One (Map k v) Source # | Create singleton
law> | ||||
Hashable k => One (HashMap k v) Source # | Create singleton
law> | ||||