relude-0.6.0.0: Custom prelude from Kowainik
Copyright(c) 2016 Stephen Diehl
(c) 2016-2018 Serokell
(c) 2018-2019 Kowainik
LicenseMIT
MaintainerKowainik <xrom.xkov@gmail.com>
Safe HaskellNone
LanguageHaskell2010

Relude.Container.One

Description

Typeclass for creating structures from a singleton element. It has three main goals:

  1. Give a shorter name for the construction: uses one instead of common singleton.
  2. Work with monomorphic structures like Text or IntSet.
  3. Give a clearer and less scary name for cases where you can use pure or (:[]).
Synopsis

Documentation

class One x where Source #

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)

Associated Types

type OneItem x Source #

Type of single element of the structure.

Methods

one :: OneItem x -> x Source #

Create a list, map, Text, etc from a single element.

Instances

Instances details
One ShortByteString Source #

Create singleton ShortByteString.

>>> one 97 :: ShortByteString
"a"
ShortByteString.length (one x) == 1
Instance details

Defined in Relude.Container.One

Associated Types

type OneItem ShortByteString Source #

One ByteString Source #

Create singleton lazy ByteString.

>>> one 97 :: LByteString
"a"
LByteString.length (one x) == 1
Instance details

Defined in Relude.Container.One

Associated Types

type OneItem ByteString Source #

One ByteString Source #

Create singleton strict ByteString.

>>> one 97 :: ByteString
"a"
ByteString.length (one x) == 1
Instance details

Defined in Relude.Container.One

Associated Types

type OneItem ByteString Source #

One IntSet Source #

Create singleton IntSet.

>>> one 42 :: IntSet
fromList [42]
IntSet.size (one x) == 1
Instance details

Defined in Relude.Container.One

Associated Types

type OneItem IntSet Source #

One Text Source #

Create singleton lazy Text.

>>> one 'a' :: LText
"a"
LText.length (one x) == 1
Instance details

Defined in Relude.Container.One

Associated Types

type OneItem Text Source #

Methods

one :: OneItem Text -> Text Source #

One Text Source #

Create singleton strict Text.

>>> one 'a' :: Text
"a"
Text.length (one x) == 1
Instance details

Defined in Relude.Container.One

Associated Types

type OneItem Text Source #

Methods

one :: OneItem Text -> Text Source #

One [a] Source #

Allows to create a singleton list. You might prefer function with name one instead of pure or (:[]).

>>> one 42 :: [Int]
[42]
length (one @[Int] x) == 1
Instance details

Defined in Relude.Container.One

Associated Types

type OneItem [a] Source #

Methods

one :: OneItem [a] -> [a] Source #

One (NonEmpty a) Source #

Allows to create singleton NonEmpty list. You might prefer function with name one instead of pure or (:|[]).

>>> one 42 :: NonEmpty Int
42 :| []
length (one @(NonEmpty Int) x) == 1
Instance details

Defined in Relude.Container.One

Associated Types

type OneItem (NonEmpty a) Source #

Methods

one :: OneItem (NonEmpty a) -> NonEmpty a Source #

One (IntMap v) Source #

Create singleton IntMap from key-value pair.

>>> one (3, "foo") :: IntMap Text
fromList [(3,"foo")]
length (one @(IntMap String) x) == 1
Instance details

Defined in Relude.Container.One

Associated Types

type OneItem (IntMap v) Source #

Methods

one :: OneItem (IntMap v) -> IntMap v Source #

One (Seq a) Source #

Create singleton Seq.

>>> one 42 :: Seq Int
fromList [42]
length (one @(Seq Int) x) == 1
Instance details

Defined in Relude.Container.One

Associated Types

type OneItem (Seq a) Source #

Methods

one :: OneItem (Seq a) -> Seq a Source #

One (Set a) Source #

Create singleton Set.

>>> one 42 :: Set Int
fromList [42]
length (one @(Set Int) x) == 1
Instance details

Defined in Relude.Container.One

Associated Types

type OneItem (Set a) Source #

Methods

one :: OneItem (Set a) -> Set a Source #

Hashable a => One (HashSet a) Source #

Create singleton HashSet.

>>> one 42 :: HashSet Int
fromList [42]
length (one @(HashSet Int) x) == 1
Instance details

Defined in Relude.Container.One

Associated Types

type OneItem (HashSet a) Source #

Methods

one :: OneItem (HashSet a) -> HashSet a Source #

One (Map k v) Source #

Create singleton Map from key-value pair.

>>> one (3, "foo") :: Map Int Text
fromList [(3,"foo")]
length (one @(Map Int String) x) == 1
Instance details

Defined in Relude.Container.One

Associated Types

type OneItem (Map k v) Source #

Methods

one :: OneItem (Map k v) -> Map k v Source #

Hashable k => One (HashMap k v) Source #

Create singleton HashMap from key-value pair.

>>> one (3, "foo") :: HashMap Int Text
fromList [(3,"foo")]
length (one @(HashMap Int String) x) == 1
Instance details

Defined in Relude.Container.One

Associated Types

type OneItem (HashMap k v) Source #

Methods

one :: OneItem (HashMap k v) -> HashMap k v Source #