HORIZON HASKELLDocslts/ghc-9.10.x248f8f02026-10-05Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · 248f8f0 · 2026-10-05

Modulerelude-1.2.0.0Haskell2010

Relude.Container.One

SPDX-License-Identifier : MIT Maintainer : Kowainik xrom.xkov@gmail.com Stability : Stable Portability : Portable

One is a 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 Relude.pure or (:[]).

  • 1 class
  • Packagerelude-1.2.0.0
  • Exports1
  • LanguageHaskell2010
  • LicenceMIT
  • SourceOne.hs
classclass One x where
#

Typeclass for data types that can be created from one element. E.g. lists, non-empty containers, maps.

Example3 expressions
one True :: [Bool][True]one 'a' :: Text"a"one (3, "hello") :: HashMap Int StringfromList [(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 family OneItem x

    Type of a single element of the structure.

Methods

  • one :: OneItem x -> x

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

Instances14One, …
  • One ByteStringDefined in relude-1.2.0.0 · Relude.Container.One

    Create singleton strict ByteString.

    Example1 expression
    one 97 :: ByteString"a"
    law> length (one x) ≡ 1
    
  • One ByteStringDefined in relude-1.2.0.0 · Relude.Container.One

    Create singleton lazy ByteString.

    Example1 expression
    one 97 :: LByteString"a"
    law> length (one x) ≡ 1
    
  • One ShortByteStringDefined in relude-1.2.0.0 · Relude.Container.One

    Create singleton ShortByteString.

    Example1 expression
    one 97 :: ShortByteString"a"
    law> length (one x) ≡ 1
    
  • One IntSetDefined in relude-1.2.0.0 · Relude.Container.One

    Create singleton IntSet.

    Example1 expression
    one 42 :: IntSetfromList [42]
    law> size (one x) ≡ 1
    
  • One TextDefined in relude-1.2.0.0 · Relude.Container.One

    Create singleton strict Text.

    Example1 expression
    one 'a' :: Text"a"
    law> length (one x) ≡ 1
    
  • One TextDefined in relude-1.2.0.0 · Relude.Container.One

    Create singleton lazy Text.

    Example1 expression
    one 'a' :: LText"a"
    law> length (one x) ≡ 1
    
  • Hashable a => One (HashSet a)Defined in relude-1.2.0.0 · Relude.Container.One

    Create singleton HashSet.

    Example1 expression
    one 42 :: HashSet IntfromList [42]
    law> Relude.length (one @(HashSet a) x) ≡ 1
    
  • One (IntMap v)Defined in relude-1.2.0.0 · Relude.Container.One

    Create singleton IntMap from key-value pair.

    Example1 expression
    one (3, "foo") :: IntMap TextfromList [(3,"foo")]
    law> Relude.length (one @(IntMap a) x) ≡ 1
    
  • One (Seq a)Defined in relude-1.2.0.0 · Relude.Container.One

    Create singleton Seq.

    Example1 expression
    one 42 :: Seq IntfromList [42]
    law> Relude.length (one @(Seq a) x) ≡ 1
    
  • One (Set a)Defined in relude-1.2.0.0 · Relude.Container.One

    Create singleton Set.

    Example1 expression
    one 42 :: Set IntfromList [42]
    law> Relude.length (one @(Set a) x) ≡ 1
    
  • One (NonEmpty a)Defined in relude-1.2.0.0 · Relude.Container.One

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

    Example1 expression
    one 42 :: NonEmpty Int42 :| []
    law> Relude.length (one @(NonEmpty a) x) ≡ 1
    
  • One [a]Defined in relude-1.2.0.0 · Relude.Container.One

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

    Example1 expression
    one 42 :: [Int][42]
    law> Relude.length (one @[a] x) ≡ 1
    
  • Hashable k => One (HashMap k v)Defined in relude-1.2.0.0 · Relude.Container.One

    Create singleton HashMap from key-value pair.

    Example1 expression
    one (3, "foo") :: HashMap Int TextfromList [(3,"foo")]
    law> Relude.length (one @(HashMap k v) (k, v)) ≡ 1
    
  • One (Map k v)Defined in relude-1.2.0.0 · Relude.Container.One

    Create singleton Map from key-value pair.

    Example1 expression
    one (3, "foo") :: Map Int TextfromList [(3,"foo")]
    law> Relude.length (one @(Map k v) (k, v)) ≡ 1