toolshed-0.11.1.0: Utilities used by other packages.

ToolShed.ListPlus

Contents

Description

AUTHOR
Dr. Alistair Ward
DESCRIPTION
Miscellaneous polymorphic list-operations.

Synopsis

Types

Type-synonyms

type ChunkLength = IntSource

The length of the chunks into which a list is split.

Functions

chunkSource

Arguments

:: ChunkLength 
-> [a]

The polymorphic input list to be chunked.

-> [[a]] 
  • Splits a list into length-size pieces, where (size >= 0).
  • The last chunk will be shorter, if n isn't an aliquot part of the input list-length.
  • If (size == 0), the resulting list will be an infinite sequence of null lists.
  • CAVEAT: a similar function is available in the module Data.List.Split, though this one checks for (size < 0).

exciseSource

Arguments

:: Int

The index.

-> [a]

The polymorphic input list.

-> [a]

The same list, with the indexed element removed.

Remove the single indexed element from the list.

groupComparingSource

Arguments

:: Eq b 
=> (a -> b)

Translates elements from the list, prior to testing the translated values for equality.

-> [a]

The polymorphic input list to group.

-> [[a]]

The same list split into chunks of the required length.

  • Much like Data.List.GroupBy, but where the normal binary predicate, is composed from equality, after the same unary translation-function has been applied to both list-elements.
  • cf. GHC.Exts.groupWith, which uses the function parameter to both sort and group.

merge :: Ord a => [a] -> [a] -> [a]Source

  • Merge two sorted lists, to product a single sorted list.
  • The merge-process is stable, in that where items from each list are equal, they remain in the original order.

mergeBy :: Ord a => (a -> a -> Ordering) -> [a] -> [a] -> [a]Source

  • Merge two sorted lists, according to the specified order, to product a single sorted list.
  • The merge-process is stable, in that where items from each list are equal, they remain in the original order.

splitsLeftFromSource

Arguments

:: Int

Index.

-> [a]

The polymorphic input list from which the splits are generated, as the index is stepped left

-> [Split a]

The list of all required splits of the single input list.

  • Create the set of all Splits, migrating left from the specified location.
  • CAVEAT: init fails when fst has been reduced to null.

splitsRightFromSource

Arguments

:: Int

Index.

-> [a]

The polymorphic input list from which the splits are generated, as the index is stepped right.

-> [Split a]

The list of all required splits of the single input list.

  • Create the set of all Splits, migrating right from the specified location.
  • CAVEAT: pattern-match against : fails, when snd has been reduced to null.

takeUntilSource

Arguments

:: (a -> Bool)

Predicate, used to determine the last item taken.

-> [a]

The polymorphic input list.

-> [a] 
  • Take until the specified predicate is satisfied; including the item which satisfied it.
  • NB: takeWhile (not . test) would return one fewer item.