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

Modulefoundation-0.0.30Haskell2010

Foundation.Collection

Different collections (list, vector, string, ..) unified under 1 API. an API to rules them all, and in the darkness bind them.

  • 3 types
  • 13 classes
  • 11 values
  • Packagefoundation-0.0.30
  • Exports28
  • LanguageHaskell2010
  • LicenceBSD-3-Clause
  • SourceCollection.hs
classclass Zippable col => BoxedZippable col where
#

Methods

Instances2BoxedZippable
  • BoxedZippable (Array ty)Defined in foundation-0.0.30 · Foundation.Collection.Zippable
  • BoxedZippable [a]Defined in foundation-0.0.30 · Foundation.Collection.Zippable
familytype family Element container
#

Element type of a collection

Instances14Element, …
  • type Element AsciiString = Char7Defined in foundation-0.0.30 · Foundation.Collection.Element
  • type Element String = CharDefined in foundation-0.0.30 · Foundation.Collection.Element
  • type Element Bitmap = BoolDefined in foundation-0.0.30 · Foundation.Array.Bitmap
  • type Element CSV = RowDefined in foundation-0.0.30 · Foundation.Format.CSV.Types
  • type Element Row = FieldDefined in foundation-0.0.30 · Foundation.Format.CSV.Types
  • type Element (Block ty) = tyDefined in foundation-0.0.30 · Foundation.Collection.Element
  • type Element (Array ty) = tyDefined in foundation-0.0.30 · Foundation.Collection.Element
  • type Element (NonEmpty a) = Element aDefined in foundation-0.0.30 · Foundation.Collection.Element
  • type Element (BlockN n ty) = tyDefined in foundation-0.0.30 · Foundation.Collection.Element
  • type Element (ListN n a) = aDefined in foundation-0.0.30 · Foundation.Collection.Element
  • type Element (UArray ty) = tyDefined in foundation-0.0.30 · Foundation.Collection.Element
  • type Element (ChunkedUArray ty) = tyDefined in foundation-0.0.30 · Foundation.Array.Chunked.Unboxed
  • type Element (DList a) = aDefined in foundation-0.0.30 · Foundation.List.DList
  • type Element [a] = aDefined in foundation-0.0.30 · Foundation.Collection.Element
classclass InnerFunctor c where
#

A monomorphic functor that maps the inner values to values of the same type

Methods

Instances5InnerFunctor
classclass Foldable collection where
#

Give the ability to fold a collection on itself

Methods

  • foldl' :: (a -> Element collection -> a) -> a -> collection -> a

    Left-associative fold of a structure.

    In the case of lists, foldl, when applied to a binary operator, a starting value (typically the left-identity of the operator), and a list, reduces the list using the binary operator, from left to right:

    foldl f z [x1, x2, ..., xn] == (...((z `f` x1) `f` x2) `f`...) `f` xn

    Note that to produce the outermost application of the operator the entire input list must be traversed. This means that foldl' will diverge if given an infinite list.

    Note that Foundation only provides foldl', a strict version of foldl because the lazy version is seldom useful.

    Left-associative fold of a structure with strict application of the operator.

  • foldr :: (Element collection -> a -> a) -> a -> collection -> a

    Right-associative fold of a structure.

    foldr f z [x1, x2, ..., xn] == x1 `f` (x2 `f` ... (xn `f` z)...)
  • foldr' :: (Element collection -> a -> a) -> a -> collection -> a

    Right-associative fold of a structure, but with strict application of the operator.

Instances9Foldable, …
  • Foldable BitmapDefined in foundation-0.0.30 · Foundation.Array.Bitmap
  • PrimType ty => Foldable (Block ty)Defined in foundation-0.0.30 · Foundation.Collection.Foldable
  • PrimType ty => Foldable (UArray ty)Defined in foundation-0.0.30 · Foundation.Collection.Foldable
  • PrimType ty => Foldable (ChunkedUArray ty)Defined in foundation-0.0.30 · Foundation.Array.Chunked.Unboxed
  • Foldable (Array ty)Defined in foundation-0.0.30 · Foundation.Collection.Foldable
  • Foldable (DList a)Defined in foundation-0.0.30 · Foundation.List.DList
  • Foldable [a]Defined in foundation-0.0.30 · Foundation.Collection.Foldable
  • PrimType ty => Foldable (BlockN n ty)Defined in foundation-0.0.30 · Foundation.Collection.Foldable
  • Foldable (ListN n a)Defined in foundation-0.0.30 · Foundation.Collection.Foldable
classclass Foldable f => Fold1able f where
#

Fold1's. Like folds, but they assume to operate on a NonEmpty collection.

Methods

Instances5Fold1able
  • PrimType ty => Fold1able (Block ty)Defined in foundation-0.0.30 · Foundation.Collection.Foldable
  • PrimType ty => Fold1able (UArray ty)Defined in foundation-0.0.30 · Foundation.Collection.Foldable
  • Fold1able (Array ty)Defined in foundation-0.0.30 · Foundation.Collection.Foldable
  • Fold1able [a]Defined in foundation-0.0.30 · Foundation.Collection.Foldable
  • 1 <= n => Fold1able (ListN n a)Defined in foundation-0.0.30 · Foundation.Collection.Foldable
classclass Functor collection => Mappable (collection :: Type -> Type) where
#

Functors representing data structures that can be traversed from left to right.

Mostly like base's Traversable but applied to collections only.

Methods

  • traverse :: Applicative f => (a -> f b) -> collection a -> f (collection b)

    Map each element of a structure to an action, evaluate these actions from left to right, and collect the results. For a version that ignores the results see traverse_.

  • sequenceA :: Applicative f => collection (f a) -> f (collection a)

    Evaluate each actions of the given collections, from left to right, and collect the results. For a version that ignores the results, see Foundation.Collection.sequenceA_

  • mapM :: (Applicative m, Monad m) => (a -> m b) -> collection a -> m (collection b)

    Map each element of the collection to an action, evaluate these actions from left to right, and collect the results. For a version that ignores the results see mapM_.

  • sequence :: (Applicative m, Monad m) => collection (m a) -> m (collection a)

    Evaluate each actions of the given collections, from left to right, and collect the results. For a version that ignores the results, see Foundation.Collection.sequence_

Instances2Mappable
  • Mappable ArrayDefined in foundation-0.0.30 · Foundation.Collection.Mappable
  • Mappable []Defined in foundation-0.0.30 · Foundation.Collection.Mappable
valuetraverse_ :: (Mappable col, Applicative f) => (a -> f b) -> col a -> f ()
#

Map each element of a collection to an action, evaluate these actions from left to right, and ignore the results. For a version that doesn't ignore the results see traverse

valuemapM_
  1. :: (Mappable col, Applicative m, Monad m)
  2. => a -> m b
  3. -> col a
  4. -> m ()
#

Evaluate each action in the collection from left to right, and ignore the results. For a version that doesn't ignore the results see sequenceA. sequenceA_ :: (Mappable col, Applicative f) => col (f a) -> f () sequenceA_ col = sequenceA col *> pure ()

Map each element of a collection to a monadic action, evaluate these actions from left to right, and ignore the results. For a version that doesn't ignore the results see mapM.

classclass (IsList c, Item c ~ Element c) => Collection c where
#

A set of methods for ordered colection

Methods

Instances12Collection, …
newtypenewtype NonEmpty a
#

NonEmpty property for any Collection

Instances6IsList, Eq, Show, Collection, Item, Element
valuenonEmpty :: Collection c => c -> Maybe (NonEmpty c)
#

Smart constructor to create a NonEmpty collection

If the collection is empty, then Nothing is returned Otherwise, the collection is wrapped in the NonEmpty property

classclass (IsList c, Item c ~ Element c, Monoid c, Collection c) => Sequential c where
#

A set of methods for ordered colection

Methods

  • take :: CountOf (Element c) -> c -> c

    Take the first @n elements of a collection

  • revTake :: CountOf (Element c) -> c -> c

    Take the last @n elements of a collection

  • drop :: CountOf (Element c) -> c -> c

    Drop the first @n elements of a collection

  • revDrop :: CountOf (Element c) -> c -> c

    Drop the last @n elements of a collection

  • splitAt :: CountOf (Element c) -> c -> (c, c)

    Split the collection at the @n'th elements

  • revSplitAt :: CountOf (Element c) -> c -> (c, c)

    Split the collection at the @n'th elements from the end

  • splitOn :: (Element c -> Bool) -> c -> [c]

    Split on a specific elements returning a list of colletion

  • break :: (Element c -> Bool) -> c -> (c, c)

    Split a collection when the predicate return true

  • breakEnd :: (Element c -> Bool) -> c -> (c, c)

    Split a collection when the predicate return true starting from the end of the collection

  • breakElem :: Eq (Element c) => Element c -> c -> (c, c)

    Split a collection at the given element

  • takeWhile :: (Element c -> Bool) -> c -> c

    Return the longest prefix in the collection that satisfy the predicate

  • dropWhile :: (Element c -> Bool) -> c -> c

    Return the longest prefix in the collection that satisfy the predicate

  • intersperse :: Element c -> c -> c

    The intersperse function takes an element and a list and `intersperses' that element between the elements of the list. For example,

    intersperse ',' "abcde" == "a,b,c,d,e"
  • intercalate :: Monoid (Item c) => Element c -> c -> Element c

    intercalate xs xss is equivalent to (mconcat (intersperse xs xss)). It inserts the list xs in between the lists in xss and concatenates the result.

  • span :: (Element c -> Bool) -> c -> (c, c)

    Split a collection while the predicate return true

  • spanEnd :: (Element c -> Bool) -> c -> (c, c)

    Split a collection while the predicate return true starting from the end of the collection

  • filter :: (Element c -> Bool) -> c -> c

    Filter all the elements that satisfy the predicate

  • partition :: (Element c -> Bool) -> c -> (c, c)

    Partition the elements that satisfy the predicate and those that don't

  • reverse :: c -> c

    Reverse a collection

  • uncons :: c -> Maybe (Element c, c)

    Decompose a collection into its first element and the remaining collection. If the collection is empty, returns Nothing.

  • unsnoc :: c -> Maybe (c, Element c)

    Decompose a collection into a collection without its last element, and the last element If the collection is empty, returns Nothing.

  • snoc :: c -> Element c -> c

    Prepend an element to an ordered collection

  • cons :: Element c -> c -> c

    Append an element to an ordered collection

  • find :: (Element c -> Bool) -> c -> Maybe (Element c)

    Find an element in an ordered collection

  • sortBy :: (Element c -> Element c -> Ordering) -> c -> c

    Sort an ordered collection using the specified order function

  • singleton :: Element c -> c

    Create a collection with a single element

  • head :: NonEmpty c -> Element c

    get the first element of a non-empty collection

  • last :: NonEmpty c -> Element c

    get the last element of a non-empty collection

  • tail :: NonEmpty c -> c

    Extract the elements after the first element of a non-empty collection.

  • init :: NonEmpty c -> c

    Extract the elements before the last element of a non-empty collection.

  • replicate :: CountOf (Element c) -> Element c -> c

    Create a collection where the element in parameter is repeated N time

  • isPrefixOf :: Eq (Element c) => c -> c -> Bool

    Takes two collections and returns True iff the first collection is a prefix of the second.

  • isSuffixOf :: Eq (Element c) => c -> c -> Bool

    Takes two collections and returns True iff the first collection is a suffix of the second.

  • isInfixOf :: Eq (Element c) => c -> c -> Bool

    Takes two collections and returns True iff the first collection is an infix of the second.

  • stripPrefix :: Eq (Element c) => c -> c -> Maybe c

    Try to strip a prefix from a collection

  • stripSuffix :: Eq (Element c) => c -> c -> Maybe c

    Try to strip a suffix from a collection

Instances11Sequential, …
classclass MutableCollection (c :: Type -> Type) where
#

Collection of things that can be made mutable, modified and then freezed into an MutableFreezed collection

Associated types

Methods

Instances4MutableCollection
classclass IndexedCollection c where
#

Collection of elements that can indexed by int

Methods

Instances11IndexedCollection, …
classclass KeyedCollection c where
#

Collection of things that can be looked up by Key

Associated types

Methods

Instances1KeyedCollection
  • Eq k => KeyedCollection [(k, v)]Defined in foundation-0.0.30 · Foundation.Collection.Keyed
classclass Sequential col => Zippable col where
#

Methods

Instances5Zippable
  • Zippable AsciiStringDefined in foundation-0.0.30 · Foundation.Collection.Zippable
  • Zippable StringDefined in foundation-0.0.30 · Foundation.Collection.Zippable
  • PrimType ty => Zippable (UArray ty)Defined in foundation-0.0.30 · Foundation.Collection.Zippable
  • Zippable (Array ty)Defined in foundation-0.0.30 · Foundation.Collection.Zippable
  • Zippable [c]Defined in foundation-0.0.30 · Foundation.Collection.Zippable
classclass Buildable col where
#

Collections that can be built chunk by chunk.

Use the Monad instance of Builder to chain append operations and feed it into build:

Example1 expression
runST $ build 32 (append 'a' >> append 'b' >> append 'c') :: UArray Char"abc"

Associated types

  • type family Mutable col :: Type -> Type

    Mutable collection type used for incrementally writing chunks.

  • type family Step col

    Unit of the smallest step possible in an append operation.

    A UTF-8 character can have a size between 1 and 4 bytes, so this should be defined as 1 byte for collections of Char.

Methods

Instances3Buildable
  • Buildable StringDefined in foundation-0.0.30 · Foundation.Collection.Buildable
  • PrimType ty => Buildable (UArray ty)Defined in foundation-0.0.30 · Foundation.Collection.Buildable
  • Buildable (Array ty)Defined in foundation-0.0.30 · Foundation.Collection.Buildable
newtypenewtype Builder collection (mutCollection :: Type -> Type) step (state :: Type -> Type) err a
#

Constructors

Instances5Monad, Functor, Applicative, MonadFailure, Failure
  • Monad state => Monad (Builder collection mutCollection step state err)Defined in basement-0.0.16 · Basement.MutableBuilder
  • Monad state => Functor (Builder collection mutCollection step state err)Defined in basement-0.0.16 · Basement.MutableBuilder
  • Monad state => Applicative (Builder collection mutCollection step state err)Defined in basement-0.0.16 · Basement.MutableBuilder
  • Monad state => MonadFailure (Builder collection mutCollection step state err)Defined in basement-0.0.16 · Basement.MutableBuilder
  • type Failure (Builder collection mutCollection step state err) = errDefined in basement-0.0.16 · Basement.MutableBuilder
classclass Copy a where
#

Methods

Instances7Copy, …
  • Copy StringDefined in foundation-0.0.30 · Foundation.Collection.Copy
  • PrimType ty => Copy (Block ty)Defined in foundation-0.0.30 · Foundation.Collection.Copy
  • PrimType ty => Copy (UArray ty)Defined in foundation-0.0.30 · Foundation.Collection.Copy
  • Copy (Array ty)Defined in foundation-0.0.30 · Foundation.Collection.Copy
  • Copy [ty]Defined in foundation-0.0.30 · Foundation.Collection.Copy
  • Copy (ListN n ty)Defined in foundation-0.0.30 · Foundation.Collection.Copy
  • (Countable ty n, PrimType ty, KnownNat n) => Copy (BlockN n ty)Defined in foundation-0.0.30 · Foundation.Collection.Copy