Data.ListLike

ListLike-4.5.1: Generic support for list-like structures

Copyright | Copyright (C) 2007 John Goerzen
License | BSD3
Maintainer | John Goerzen <jgoerzen@complete.org>
Stability | provisional
Portability | portable
Safe Haskell | None
Language | Haskell98

Data.ListLike

Contents

- Introduction
- Creation & Basic Functions
- List transformations
  - Conversions
- Reducing lists (folds), from FoldableLL
  - Special folds
- Building lists
  - Scans
  - Accumulating maps
  - Infinite lists
  - Unfolding
- Sublists
  - Extracting sublists
  - Predicates
  - Modify based on predicate
- Searching lists
  - Searching by equality
  - Searching with a predicate
- Indexing lists
- Zipping and unzipping lists
- Monadic Operations
- Input and Output
- Special lists
  - Strings
  - "Set" operations
  - Ordered lists
- Generalized functions
  - The "By" operations
    - User-supplied equality (replacing an Eq context)
    - User-supplied comparison (replacing an Ord context)
  - The "generic" operations
- Notes on specific instances
  - Lists
  - Arrays
  - ByteStrings
- Base Typeclasses
  - The ListLike class
  - The FoldableLL class
  - The StringLike class
  - The InfiniteListLike class

Description

Generic operations over list-like structures

Written by John Goerzen, jgoerzen@complete.org

Please start with the introduction at Data.ListLike.

Synopsis

- empty :: ListLike full item => full
- singleton :: ListLike full item => item -> full
- cons :: ListLike full item => item -> full -> full
- snoc :: ListLike full item => full -> item -> full
- append :: ListLike full item => full -> full -> full
- uncons :: ListLike full item => full -> Maybe (item, full)
- head :: ListLike full item => full -> item
- last :: ListLike full item => full -> item
- tail :: ListLike full item => full -> full
- init :: ListLike full item => full -> full
- null :: ListLike full item => full -> Bool
- length :: ListLike full item => full -> Int
- map :: (ListLike full item, ListLike full' item') => (item -> item') -> full -> full'
- rigidMap :: ListLike full item => (item -> item) -> full -> full
- reverse :: ListLike full item => full -> full
- intersperse :: ListLike full item => item -> full -> full
- toList :: ListLike full item => full -> [item]
- fromList :: ListLike full item => [item] -> full
- fromListLike :: (ListLike full item, ListLike full' item) => full -> full'
- foldl :: FoldableLL full item => (a -> item -> a) -> a -> full -> a
- foldl' :: FoldableLL full item => (a -> item -> a) -> a -> full -> a
- foldl1 :: FoldableLL full item => (item -> item -> item) -> full -> item
- foldr :: FoldableLL full item => (item -> b -> b) -> b -> full -> b
- foldr' :: FoldableLL full item => (item -> b -> b) -> b -> full -> b
- foldr1 :: FoldableLL full item => (item -> item -> item) -> full -> item
- concat :: (ListLike full item, ListLike full' full, Monoid full) => full' -> full
- concatMap :: (ListLike full item, ListLike full' item') => (item -> full') -> full -> full'
- rigidConcatMap :: ListLike full item => (item -> full) -> full -> full
- and :: ListLike full Bool => full -> Bool
- or :: ListLike full Bool => full -> Bool
- any :: ListLike full item => (item -> Bool) -> full -> Bool
- all :: ListLike full item => (item -> Bool) -> full -> Bool
- sum :: (Num a, ListLike full a) => full -> a
- product :: (Num a, ListLike full a) => full -> a
- maximum :: (ListLike full item, Ord item) => full -> item
- minimum :: (ListLike full item, Ord item) => full -> item
- fold :: (FoldableLL full item, Monoid item) => full -> item
- foldMap :: (FoldableLL full item, Monoid m) => (item -> m) -> full -> m
- iterate :: InfiniteListLike full item => (item -> item) -> item -> full
- repeat :: InfiniteListLike full item => item -> full
- replicate :: ListLike full item => Int -> item -> full
- cycle :: InfiniteListLike full item => full -> full
- take :: ListLike full item => Int -> full -> full
- drop :: ListLike full item => Int -> full -> full
- splitAt :: ListLike full item => Int -> full -> (full, full)
- takeWhile :: ListLike full item => (item -> Bool) -> full -> full
- dropWhile :: ListLike full item => (item -> Bool) -> full -> full
- dropWhileEnd :: ListLike full item => (item -> Bool) -> full -> full
- span :: ListLike full item => (item -> Bool) -> full -> (full, full)
- break :: ListLike full item => (item -> Bool) -> full -> (full, full)
- group :: (ListLike full item, ListLike full' full, Eq item) => full -> full'
- inits :: (ListLike full item, ListLike full' full) => full -> full'
- tails :: (ListLike full item, ListLike full' full) => full -> full'
- isPrefixOf :: (ListLike full item, Eq item) => full -> full -> Bool
- isSuffixOf :: (ListLike full item, Eq item) => full -> full -> Bool
- isInfixOf :: (ListLike full item, Eq item) => full -> full -> Bool
- stripPrefix :: (ListLike full item, Eq item) => full -> full -> Maybe full
- stripSuffix :: (ListLike full item, Eq item) => full -> full -> Maybe full
- elem :: (ListLike full item, Eq item) => item -> full -> Bool
- notElem :: (ListLike full item, Eq item) => item -> full -> Bool
- find :: ListLike full item => (item -> Bool) -> full -> Maybe item
- filter :: ListLike full item => (item -> Bool) -> full -> full
- partition :: ListLike full item => (item -> Bool) -> full -> (full, full)
- index :: ListLike full item => full -> Int -> item
- elemIndex :: (ListLike full item, Eq item) => item -> full -> Maybe Int
- elemIndices :: (ListLike full item, Eq item, ListLike result Int) => item -> full -> result
- findIndex :: ListLike full item => (item -> Bool) -> full -> Maybe Int
- findIndices :: (ListLike full item, ListLike result Int) => (item -> Bool) -> full -> result
- zip :: (ListLike full item, ListLike fullb itemb, ListLike result (item, itemb)) => full -> fullb -> result
- zipWith :: (ListLike full item, ListLike fullb itemb, ListLike result resultitem) => (item -> itemb -> resultitem) -> full -> fullb -> result
- unzip :: (ListLike full (itema, itemb), ListLike ra itema, ListLike rb itemb) => full -> (ra, rb)
- sequence :: (ListLike full item, Monad m, ListLike fullinp (m item)) => fullinp -> m full
- sequence_ :: (Monad m, FoldableLL full (m item)) => full -> m ()
- mapM :: (ListLike full item, Monad m, ListLike full' item') => (item -> m item') -> full -> m full'
- rigidMapM :: (ListLike full item, Monad m) => (item -> m item) -> full -> m full
- mapM_ :: (Monad m, FoldableLL full item) => (item -> m b) -> full -> m ()
- class ListLike full item => ListLikeIO full item | full -> item where
- toString :: StringLike s => s -> String
- fromString :: StringLike s => String -> s
- lines :: (StringLike s, ListLike full s) => s -> full
- words :: (StringLike s, ListLike full s) => s -> full
- nub :: (ListLike full item, Eq item) => full -> full
- delete :: (ListLike full item, Eq item) => item -> full -> full
- deleteFirsts :: (ListLike full item, Eq item) => full -> full -> full
- union :: (ListLike full item, Eq item) => full -> full -> full
- intersect :: (ListLike full item, Eq item) => full -> full -> full
- sort :: (ListLike full item, Ord item) => full -> full
- insert :: (ListLike full item, Ord item) => item -> full -> full
- nubBy :: ListLike full item => (item -> item -> Bool) -> full -> full
- deleteBy :: ListLike full item => (item -> item -> Bool) -> item -> full -> full
- deleteFirstsBy :: ListLike full item => (item -> item -> Bool) -> full -> full -> full
- unionBy :: ListLike full item => (item -> item -> Bool) -> full -> full -> full
- intersectBy :: ListLike full item => (item -> item -> Bool) -> full -> full -> full
- groupBy :: (ListLike full item, ListLike full' full, Eq item) => (item -> item -> Bool) -> full -> full'
- sortBy :: ListLike full item => (item -> item -> Ordering) -> full -> full
- insertBy :: ListLike full item => (item -> item -> Ordering) -> item -> full -> full
- genericLength :: (ListLike full item, Num a) => full -> a
- genericTake :: (ListLike full item, Integral a) => a -> full -> full
- genericDrop :: (ListLike full item, Integral a) => a -> full -> full
- genericSplitAt :: (ListLike full item, Integral a) => a -> full -> (full, full)
- genericReplicate :: (ListLike full item, Integral a) => a -> item -> full
- data Chars
  - = B Builder
  - | T Text
- newtype CharString = CS {
  - unCS :: ByteString
  }
- newtype CharStringLazy = CSL {
  - unCSL :: ByteString
  }
- class (FoldableLL full item, Monoid full) => ListLike full item | full -> item where
- class FoldableLL full item | full -> item where
- class StringLike s where
- class ListLike full item => InfiniteListLike full item | full -> item where

# Introduction

Welcome to ListLike.

This module provides abstractions over typical list operations. It is designed to let you freely interchange different ways to represent sequences of data. It works with lists, various types of ByteStrings, and much more.

In this module, you'll find generic versions of most of the functions you're used to using in the Prelude, Data.List, and System.IO. They carry the same names, too. Therefore, you'll want to be careful how you import the module. I suggest using:

    import qualified Data.ListLike as LL

Then, you can use LL.fold, LL.map, etc. to get the generic version of the functions you want. Alternatively, you can hide the other versions from Prelude and import specific generic functions from here, such as:

    import Prelude hiding (map)
    import Data.ListLike (map)

The module Data.ListLike actually simply re-exports the items found in a number of its sub-modules. If you want a smaller subset of Data.ListLike, look at the documentation for its sub-modules and import the relevant one.

In most cases, functions here can act as drop-in replacements for their list-specific counterparts. They will use the same underlying implementations for lists, so there should be no performance difference.

You can make your own types instances of `ListLike` as well. For more details, see the notes for the `ListLike` typeclass.

# Creation & Basic Functions

empty :: ListLike full item => full #

The empty list

singleton :: ListLike full item => item -> full #

Creates a single-element list out of an element

cons :: ListLike full item => item -> full -> full #

Like (:) for lists: adds an element to the beginning of a list

snoc :: ListLike full item => full -> item -> full #

Adds an element to the *end* of a `ListLike`.

append :: ListLike full item => full -> full -> full #

Combines two lists. Like (++).

uncons :: ListLike full item => full -> Maybe (item, full) #

Extract head and tail, return Nothing if empty

head :: ListLike full item => full -> item #

Extracts the first element of a `ListLike`.

last :: ListLike full item => full -> item #

Extracts the last element of a `ListLike`.

tail :: ListLike full item => full -> full #

Gives all elements after the head.

init :: ListLike full item => full -> full #

All elements of the list except the last one. See also `inits`.

null :: ListLike full item => full -> Bool #

Tests whether the list is empty.

length :: ListLike full item => full -> Int #

Length of the list. See also `genericLength`.

# List transformations

map :: (ListLike full item, ListLike full' item') => (item -> item') -> full -> full' #

Apply a function to each element, returning any other valid `ListLike`. `rigidMap` will always be at least as fast, if not faster, than this function and is recommended if it will work for your purposes. See also `mapM`.

rigidMap :: ListLike full item => (item -> item) -> full -> full #

Like `map`, but without the possibility of changing the type of the item. This can have performance benefits for things such as ByteStrings, since it will let the ByteString use its native low-level map implementation.

reverse :: ListLike full item => full -> full #

Reverse the elements in a list.

intersperse :: ListLike full item => item -> full -> full #

Add an item between each element in the structure

## Conversions

toList :: ListLike full item => full -> [item] #

Converts the structure to a list. This is logically equivolent to `fromListLike`, but may have a more optimized implementation.

fromList :: ListLike full item => [item] -> full #

Generates the structure from a list.

fromListLike :: (ListLike full item, ListLike full' item) => full -> full' #

Converts one ListLike to another. See also `toList`. Default implementation is `fromListLike = map id`

# Reducing lists (folds), from FoldableLL

foldl :: FoldableLL full item => (a -> item -> a) -> a -> full -> a #

Left-associative fold

foldl' :: FoldableLL full item => (a -> item -> a) -> a -> full -> a #

Strict version of `foldl`.

foldl1 :: FoldableLL full item => (item -> item -> item) -> full -> item #

A variant of `foldl` with no base case. Requires at least 1 list element.

foldr :: FoldableLL full item => (item -> b -> b) -> b -> full -> b #

Right-associative fold

foldr' :: FoldableLL full item => (item -> b -> b) -> b -> full -> b #

Strict version of `foldr`

foldr1 :: FoldableLL full item => (item -> item -> item) -> full -> item #

Like `foldr`, but with no starting value

## Special folds

concat :: (ListLike full item, ListLike full' full, Monoid full) => full' -> full #

Flatten the structure.

concatMap :: (ListLike full item, ListLike full' item') => (item -> full') -> full -> full' #

Map a function over the items and concatenate the results. See also `rigidConcatMap`.

rigidConcatMap :: ListLike full item => (item -> full) -> full -> full #

Like `concatMap`, but without the possibility of changing the type of the item. This can have performance benefits for some things such as ByteString.

and :: ListLike full Bool => full -> Bool #

Returns True if all elements are True

or :: ListLike full Bool => full -> Bool #

Returns True if any element is True

any :: ListLike full item => (item -> Bool) -> full -> Bool #

True if any items satisfy the function

all :: ListLike full item => (item -> Bool) -> full -> Bool #

True if all items satisfy the function

sum :: (Num a, ListLike full a) => full -> a #

The sum of the list

product :: (Num a, ListLike full a) => full -> a #

The product of the list

maximum :: (ListLike full item, Ord item) => full -> item #

The maximum value of the list

minimum :: (ListLike full item, Ord item) => full -> item #

The minimum value of the list

fold :: (FoldableLL full item, Monoid item) => full -> item #

Combine the elements of a structure using a monoid. ``fold` = `foldMap` id`

foldMap :: (FoldableLL full item, Monoid m) => (item -> m) -> full -> m #

Map each element to a monoid, then combine the results

# Building lists

## Scans

## Accumulating maps

## Infinite lists

iterate :: InfiniteListLike full item => (item -> item) -> item -> full #

An infinite list of repeated calls of the function to args

repeat :: InfiniteListLike full item => item -> full #

An infinite list where each element is the same

replicate :: ListLike full item => Int -> item -> full #

Generate a structure with the specified length with every element set to the item passed in. See also `genericReplicate`

cycle :: InfiniteListLike full item => full -> full #

Converts a finite list into a circular one

## Unfolding

# Sublists

## Extracting sublists

take :: ListLike full item => Int -> full -> full #

Takes the first n elements of the list. See also `genericTake`.

drop :: ListLike full item => Int -> full -> full #

Drops the first n elements of the list. See also `genericDrop`

splitAt :: ListLike full item => Int -> full -> (full, full) #

Equivalent to `(`take` n xs, `drop` n xs)`. See also `genericSplitAt`.

takeWhile :: ListLike full item => (item -> Bool) -> full -> full #

Returns all elements at start of list that satisfy the function.

dropWhile :: ListLike full item => (item -> Bool) -> full -> full #

Drops all elements from the start of the list that satisfy the function.

dropWhileEnd :: ListLike full item => (item -> Bool) -> full -> full #

Drops all elements from the end of the list that satisfy the function.

span :: ListLike full item => (item -> Bool) -> full -> (full, full) #

The equivalent of `(`takeWhile` f xs, `dropWhile` f xs)`

break :: ListLike full item => (item -> Bool) -> full -> (full, full) #

The equivalent of ``span` (`not` . f)`

group :: (ListLike full item, ListLike full' full, Eq item) => full -> full' #

Split a list into sublists, each which contains equal arguments. For order-preserving types, concatenating these sublists will produce the original list. See also `groupBy`.

inits :: (ListLike full item, ListLike full' full) => full -> full' #

All initial segments of the list, shortest first

tails :: (ListLike full item, ListLike full' full) => full -> full' #

All final segnemts, longest first

## Predicates

isPrefixOf :: (ListLike full item, Eq item) => full -> full -> Bool #

True when the first list is at the beginning of the second.

isSuffixOf :: (ListLike full item, Eq item) => full -> full -> Bool #

True when the first list is at the beginning of the second.

isInfixOf :: (ListLike full item, Eq item) => full -> full -> Bool #

True when the first list is wholly containted within the second

## Modify based on predicate

stripPrefix :: (ListLike full item, Eq item) => full -> full -> Maybe full #

Remove a prefix from a listlike if possible

stripSuffix :: (ListLike full item, Eq item) => full -> full -> Maybe full #

Remove a suffix from a listlike if possible

# Searching lists

## Searching by equality

elem :: (ListLike full item, Eq item) => item -> full -> Bool #

True if the item occurs in the list

notElem :: (ListLike full item, Eq item) => item -> full -> Bool #

True if the item does not occur in the list

## Searching with a predicate

find :: ListLike full item => (item -> Bool) -> full -> Maybe item #

Take a function and return the first matching element, or Nothing if there is no such element.

filter :: ListLike full item => (item -> Bool) -> full -> full #

Returns only the elements that satisfy the function.

partition :: ListLike full item => (item -> Bool) -> full -> (full, full) #

Returns the lists that do and do not satisfy the function. Same as `(`filter` p xs, `filter` (`not` . p) xs)`

# Indexing lists

index :: ListLike full item => full -> Int -> item #

The element at 0-based index i. Raises an exception if i is out of bounds. Like (!!) for lists.

elemIndex :: (ListLike full item, Eq item) => item -> full -> Maybe Int #

Returns the index of the element, if it exists.

elemIndices :: (ListLike full item, Eq item, ListLike result Int) => item -> full -> result #

Returns the indices of the matching elements. See also `findIndices`

findIndex :: ListLike full item => (item -> Bool) -> full -> Maybe Int #

Take a function and return the index of the first matching element, or Nothing if no element matches

findIndices :: (ListLike full item, ListLike result Int) => (item -> Bool) -> full -> result #

Returns the indices of all elements satisfying the function

# Zipping and unzipping lists

zip :: (ListLike full item, ListLike fullb itemb, ListLike result (item, itemb)) => full -> fullb -> result #

Takes two lists and returns a list of corresponding pairs.

zipWith :: (ListLike full item, ListLike fullb itemb, ListLike result resultitem) => (item -> itemb -> resultitem) -> full -> fullb -> result #

Takes two lists and combines them with a custom combining function

unzip :: (ListLike full (itema, itemb), ListLike ra itema, ListLike rb itemb) => full -> (ra, rb) #

Converts a list of pairs into two separate lists of elements

# Monadic Operations

sequence :: (ListLike full item, Monad m, ListLike fullinp (m item)) => fullinp -> m full #

Evaluate each action in the sequence and collect the results

sequence_ :: (Monad m, FoldableLL full (m item)) => full -> m () #

Evaluate each action, ignoring the results. Same as ``mapM_` `id``.

mapM :: (ListLike full item, Monad m, ListLike full' item') => (item -> m item') -> full -> m full' #

A map in monad space. Same as ``sequence` . `map``

See also `rigidMapM`

rigidMapM :: (ListLike full item, Monad m) => (item -> m item) -> full -> m full #

Like `mapM`, but without the possibility of changing the type of the item. This can have performance benefits with some types.

mapM_ :: (Monad m, FoldableLL full item) => (item -> m b) -> full -> m () #

A map in monad space, discarding results.

# Input and Output

class ListLike full item => ListLikeIO full item | full -> item where #

An extension to `ListLike` for those data types that support I/O. These functions mirror those in System.IO for the most part. They also share the same names; see the comments in Data.ListLike for help importing them.

Note that some types may not be capable of lazy reading or writing. Therefore, the usual semantics of System.IO functions regarding laziness may or may not be available from a particular implementation.

Minimal complete definition:

- hGetLine
- hGetContents
- hGet
- hGetNonBlocking
- hPutStr

Minimal complete definition

hGetLine, hGetContents, hGet, hGetNonBlocking, hPutStr

Methods

hGetLine :: Handle -> IO full #

Reads a line from the specified handle

hGetContents :: Handle -> IO full #

Read entire handle contents. May be done lazily like `hGetContents`.

hGet :: Handle -> Int -> IO full #

Read specified number of bytes. See `hGet` for particular semantics.

hGetNonBlocking :: Handle -> Int -> IO full #

Non-blocking read. See `hGetNonBlocking` for more.

hPutStr :: Handle -> full -> IO () #

Writing entire data.

hPutStrLn :: Handle -> full -> IO () #

Write data plus newline character.

getLine :: IO full #

Read one line

getContents :: IO full #

Read entire content from stdin. See `hGetContents`.

putStr :: full -> IO () #

Write data to stdout.

putStrLn :: full -> IO () #

Write data plus newline character to stdout.

interact :: (full -> full) -> IO () #

Interact with stdin and stdout by using a function to transform input to output. May be lazy. See `interact` for more.

readFile :: FilePath -> IO full #

Read file. May be lazy.

writeFile :: FilePath -> full -> IO () #

Write data to file.

appendFile :: FilePath -> full -> IO () #

Append data to file.

Instances

ListLikeIO CharStringLazy Char # |
Methods hGetLine :: Handle -> IO CharStringLazy # hGetContents :: Handle -> IO CharStringLazy # hGet :: Handle -> Int -> IO CharStringLazy # hGetNonBlocking :: Handle -> Int -> IO CharStringLazy # hPutStr :: Handle -> CharStringLazy -> IO () # hPutStrLn :: Handle -> CharStringLazy -> IO () # getLine :: IO CharStringLazy # getContents :: IO CharStringLazy # putStr :: CharStringLazy -> IO () # putStrLn :: CharStringLazy -> IO () # interact :: (CharStringLazy -> CharStringLazy) -> IO () # readFile :: FilePath -> IO CharStringLazy # writeFile :: FilePath -> CharStringLazy -> IO () # appendFile :: FilePath -> CharStringLazy -> IO () #
ListLikeIO CharString Char # |
Methods hGetLine :: Handle -> IO CharString # hGetContents :: Handle -> IO CharString # hGet :: Handle -> Int -> IO CharString # hGetNonBlocking :: Handle -> Int -> IO CharString # hPutStr :: Handle -> CharString -> IO () # hPutStrLn :: Handle -> CharString -> IO () # getLine :: IO CharString # getContents :: IO CharString # putStr :: CharString -> IO () # putStrLn :: CharString -> IO () # interact :: (CharString -> CharString) -> IO () # readFile :: FilePath -> IO CharString # writeFile :: FilePath -> CharString -> IO () # appendFile :: FilePath -> CharString -> IO () #
ListLikeIO Chars Char # |
Methods hGetLine :: Handle -> IO Chars # hGetContents :: Handle -> IO Chars # hGet :: Handle -> Int -> IO Chars # hGetNonBlocking :: Handle -> Int -> IO Chars # hPutStr :: Handle -> Chars -> IO () # hPutStrLn :: Handle -> Chars -> IO () # getLine :: IO Chars # getContents :: IO Chars # putStr :: Chars -> IO () # putStrLn :: Chars -> IO () # interact :: (Chars -> Chars) -> IO () # readFile :: FilePath -> IO Chars # writeFile :: FilePath -> Chars -> IO () # appendFile :: FilePath -> Chars -> IO () #

# Special lists

## Strings

toString :: StringLike s => s -> String #

Converts the structure to a `String`

fromString :: StringLike s => String -> s #

Converts a `String` to a list

lines :: (StringLike s, ListLike full s) => s -> full #

Breaks a string into a list of strings

words :: (StringLike s, ListLike full s) => s -> full #

Breaks a string into a list of words

## "Set" operations

nub :: (ListLike full item, Eq item) => full -> full #

Removes duplicate elements from the list. See also `nubBy`

delete :: (ListLike full item, Eq item) => item -> full -> full #

Removes the first instance of the element from the list. See also `deleteBy`

deleteFirsts :: (ListLike full item, Eq item) => full -> full -> full #

List difference. Removes from the first list the first instance of each element of the second list. See '(\)' and `deleteFirstsBy`

union :: (ListLike full item, Eq item) => full -> full -> full #

List union: the set of elements that occur in either list. Duplicate elements in the first list will remain duplicate. See also `unionBy`.

intersect :: (ListLike full item, Eq item) => full -> full -> full #

List intersection: the set of elements that occur in both lists. See also `intersectBy`

## Ordered lists

sort :: (ListLike full item, Ord item) => full -> full #

Sorts the list. On data types that do not preserve ordering, or enforce their own ordering, the result may not be what you expect. See also `sortBy`.

insert :: (ListLike full item, Ord item) => item -> full -> full #

Inserts the element at the last place where it is still less than or equal to the next element. On data types that do not preserve ordering, or enforce their own ordering, the result may not be what you expect. On types such as maps, this may result in changing an existing item. See also `insertBy`.

# Generalized functions

## The "By" operations

### User-supplied equality (replacing an Eq context)

nubBy :: ListLike full item => (item -> item -> Bool) -> full -> full #

Generic version of `nub`

deleteBy :: ListLike full item => (item -> item -> Bool) -> item -> full -> full #

Generic version of `deleteBy`

deleteFirstsBy :: ListLike full item => (item -> item -> Bool) -> full -> full -> full #

Generic version of `deleteFirsts`

unionBy :: ListLike full item => (item -> item -> Bool) -> full -> full -> full #

Generic version of `union`

intersectBy :: ListLike full item => (item -> item -> Bool) -> full -> full -> full #

Generic version of `intersect`

groupBy :: (ListLike full item, ListLike full' full, Eq item) => (item -> item -> Bool) -> full -> full' #

Generic version of `group`.

### User-supplied comparison (replacing an Ord context)

sortBy :: ListLike full item => (item -> item -> Ordering) -> full -> full #

Sort function taking a custom comparison function

insertBy :: ListLike full item => (item -> item -> Ordering) -> item -> full -> full #

Like `insert`, but with a custom comparison function

## The "generic" operations

genericLength :: (ListLike full item, Num a) => full -> a #

Length of the list

genericTake :: (ListLike full item, Integral a) => a -> full -> full #

Generic version of `take`

genericDrop :: (ListLike full item, Integral a) => a -> full -> full #

Generic version of `drop`

genericSplitAt :: (ListLike full item, Integral a) => a -> full -> (full, full) #

Generic version of `splitAt`

genericReplicate :: (ListLike full item, Integral a) => a -> item -> full #

Generic version of `replicate`

# Notes on specific instances

## Lists

Functions for operating on regular lists almost all use the native implementations in Data.List, Prelude, or similar standard modules. The exceptions are:

- `mapM` uses the default `ListLike` implementation
- `hGet` does not exist for `String` in the Haskell modules. It is implemented in terms of Data.ByteString.Lazy.
- `hGetNonBlocking` is the same way.

## Arrays

`Array` is an instance of `ListLike`. Here are some notes about it:

- The index you use must be an integral
- `ListLike` functions that take an index always take a 0-based index for compatibility with other `ListLike` instances. This is translated by the instance functions into the proper offset from the bounds in the Array.
- `ListLike` functions preserve the original Array index numbers when possible. Functions such as `cons` will reduce the lower bound to do their job. `snoc` and `append` increase the upper bound. `drop` raises the lower bound and `take` lowers the upper bound.
- Functions that change the length of the array by an amount not known in advance, such as `filter`, will generate a new array with the lower bound set to 0. Furthermore, these functions cannot operate on infinite lists because they must know their length in order to generate the array. `hGetContents` and its friends will therefore require the entire file to be read into memory before processing is possible.
- `empty`, `singleton`, and `fromList` also generate an array with the lower bound set to 0.
- Many of these functions will generate runtime exceptions if you have not assigned a value to every slot in the array.

## ByteStrings

Both strict and lazy ByteStreams can be used with `ListLike`.

ByteString ListLike instances operate on `Word8` elements. This is because both Data.ByteString.ByteString and Data.ByteString.Char8.ByteString have the same underlying type. If you wish to use the Char8 representation, the newtype wrappers `CharString` and `CharStringLazy` are available.

Most `ListLike` operations map directly to ByteStream options. Notable exceptions:

- `map` uses the `ListLike` implementation. `rigidMap` is more efficient. The same goes for `concatMap` vs. `rigidConcatMap`.
- `isInfixOf`, `sequence`, `mapM` and similar monad operations, `insert`, `union`, `intersect`, `sortBy`, and similar functions are not implemented in `ByteStream` and use a naive default implementation.
- The lazy ByteStream module implements fewer funtions than the strict ByteStream module. In some cases, default implementations are used. In others, notably related to I/O, the lazy ByteStreams are converted back and forth to strict ones as appropriate.

data Chars #

Constructors

B Builder |
T Text |

Instances

Eq Chars # |
Methods (==) :: Chars -> Chars -> Bool # (/=) :: Chars -> Chars -> Bool #
Ord Chars # |
Methods compare :: Chars -> Chars -> Ordering # (<) :: Chars -> Chars -> Bool # (<=) :: Chars -> Chars -> Bool # (>) :: Chars -> Chars -> Bool # (>=) :: Chars -> Chars -> Bool # max :: Chars -> Chars -> Chars # min :: Chars -> Chars -> Chars #
Show Chars # |
Methods showsPrec :: Int -> Chars -> ShowS # show :: Chars -> String # showList :: [Chars] -> ShowS #
IsString Chars # |
Methods fromString :: String -> Chars #
Monoid Chars # |
Methods mempty :: Chars # mappend :: Chars -> Chars -> Chars # mconcat :: [Chars] -> Chars #
NFData Chars # |
Methods rnf :: Chars -> () #
StringLike Chars # |
Methods toString :: Chars -> String # fromString :: String -> Chars # lines :: ListLike full Chars => Chars -> full # words :: ListLike full Chars => Chars -> full # unlines :: ListLike full Chars => full -> Chars # unwords :: ListLike full Chars => full -> Chars #
FoldableLL Chars Char # |
Methods foldl :: (a -> Char -> a) -> a -> Chars -> a # foldl' :: (a -> Char -> a) -> a -> Chars -> a # foldl1 :: (Char -> Char -> Char) -> Chars -> Char # foldr :: (Char -> b -> b) -> b -> Chars -> b # foldr' :: (Char -> b -> b) -> b -> Chars -> b # foldr1 :: (Char -> Char -> Char) -> Chars -> Char #
ListLike Chars Char # |
Methods empty :: Chars # singleton :: Char -> Chars # cons :: Char -> Chars -> Chars # snoc :: Chars -> Char -> Chars # append :: Chars -> Chars -> Chars # head :: Chars -> Char # uncons :: Chars -> Maybe (Char, Chars) # last :: Chars -> Char # tail :: Chars -> Chars # init :: Chars -> Chars # null :: Chars -> Bool # length :: Chars -> Int # map :: ListLike full' item' => (Char -> item') -> Chars -> full' # rigidMap :: (Char -> Char) -> Chars -> Chars # reverse :: Chars -> Chars # intersperse :: Char -> Chars -> Chars # concat :: (ListLike full' Chars, Monoid Chars) => full' -> Chars # concatMap :: ListLike full' item' => (Char -> full') -> Chars -> full' # rigidConcatMap :: (Char -> Chars) -> Chars -> Chars # any :: (Char -> Bool) -> Chars -> Bool # all :: (Char -> Bool) -> Chars -> Bool # maximum :: Chars -> Char # minimum :: Chars -> Char # replicate :: Int -> Char -> Chars # take :: Int -> Chars -> Chars # drop :: Int -> Chars -> Chars # splitAt :: Int -> Chars -> (Chars, Chars) # takeWhile :: (Char -> Bool) -> Chars -> Chars # dropWhile :: (Char -> Bool) -> Chars -> Chars # dropWhileEnd :: (Char -> Bool) -> Chars -> Chars # span :: (Char -> Bool) -> Chars -> (Chars, Chars) # break :: (Char -> Bool) -> Chars -> (Chars, Chars) # group :: (ListLike full' Chars, Eq Char) => Chars -> full' # inits :: ListLike full' Chars => Chars -> full' # tails :: ListLike full' Chars => Chars -> full' # isPrefixOf :: Chars -> Chars -> Bool # isSuffixOf :: Chars -> Chars -> Bool # isInfixOf :: Chars -> Chars -> Bool # stripPrefix :: Chars -> Chars -> Maybe Chars # stripSuffix :: Chars -> Chars -> Maybe Chars # elem :: Char -> Chars -> Bool # notElem :: Char -> Chars -> Bool # find :: (Char -> Bool) -> Chars -> Maybe Char # filter :: (Char -> Bool) -> Chars -> Chars # partition :: (Char -> Bool) -> Chars -> (Chars, Chars) # index :: Chars -> Int -> Char # elemIndex :: Char -> Chars -> Maybe Int # elemIndices :: (Eq Char, ListLike result Int) => Char -> Chars -> result # findIndex :: (Char -> Bool) -> Chars -> Maybe Int # findIndices :: ListLike result Int => (Char -> Bool) -> Chars -> result # sequence :: (Monad m, ListLike fullinp (m Char)) => fullinp -> m Chars # mapM :: (Monad m, ListLike full' item') => (Char -> m item') -> Chars -> m full' # rigidMapM :: Monad m => (Char -> m Char) -> Chars -> m Chars # nub :: Chars -> Chars # delete :: Char -> Chars -> Chars # deleteFirsts :: Chars -> Chars -> Chars # union :: Chars -> Chars -> Chars # intersect :: Chars -> Chars -> Chars # sort :: Chars -> Chars # insert :: Char -> Chars -> Chars # toList :: Chars -> [Char] # fromList :: [Char] -> Chars # fromListLike :: ListLike full' Char => Chars -> full' # nubBy :: (Char -> Char -> Bool) -> Chars -> Chars # deleteBy :: (Char -> Char -> Bool) -> Char -> Chars -> Chars # deleteFirstsBy :: (Char -> Char -> Bool) -> Chars -> Chars -> Chars # unionBy :: (Char -> Char -> Bool) -> Chars -> Chars -> Chars # intersectBy :: (Char -> Char -> Bool) -> Chars -> Chars -> Chars # groupBy :: (ListLike full' Chars, Eq Char) => (Char -> Char -> Bool) -> Chars -> full' # sortBy :: (Char -> Char -> Ordering) -> Chars -> Chars # insertBy :: (Char -> Char -> Ordering) -> Char -> Chars -> Chars # genericLength :: Num a => Chars -> a # genericTake :: Integral a => a -> Chars -> Chars # genericDrop :: Integral a => a -> Chars -> Chars # genericSplitAt :: Integral a => a -> Chars -> (Chars, Chars) # genericReplicate :: Integral a => a -> Char -> Chars #
ListLikeIO Chars Char # |
Methods hGetLine :: Handle -> IO Chars # hGetContents :: Handle -> IO Chars # hGet :: Handle -> Int -> IO Chars # hGetNonBlocking :: Handle -> Int -> IO Chars # hPutStr :: Handle -> Chars -> IO () # hPutStrLn :: Handle -> Chars -> IO () # getLine :: IO Chars # getContents :: IO Chars # putStr :: Chars -> IO () # putStrLn :: Chars -> IO () # interact :: (Chars -> Chars) -> IO () # readFile :: FilePath -> IO Chars # writeFile :: FilePath -> Chars -> IO () # appendFile :: FilePath -> Chars -> IO () #

newtype CharString #

Newtype wrapper around Data.ByteString.Char8.ByteString, this allows for ListLike instances with Char elements.

Constructors

CS |
Fields unCS :: ByteString

Instances

Eq CharString # |
Methods (==) :: CharString -> CharString -> Bool # (/=) :: CharString -> CharString -> Bool #
Ord CharString # |
Methods compare :: CharString -> CharString -> Ordering # (<) :: CharString -> CharString -> Bool # (<=) :: CharString -> CharString -> Bool # (>) :: CharString -> CharString -> Bool # (>=) :: CharString -> CharString -> Bool # max :: CharString -> CharString -> CharString # min :: CharString -> CharString -> CharString #
Read CharString # |
Methods readsPrec :: Int -> ReadS CharString # readList :: ReadS [CharString] # readPrec :: ReadPrec CharString # readListPrec :: ReadPrec [CharString] #
Show CharString # |
Methods showsPrec :: Int -> CharString -> ShowS # show :: CharString -> String # showList :: [CharString] -> ShowS #
Monoid CharString # |
Methods mempty :: CharString # mappend :: CharString -> CharString -> CharString # mconcat :: [CharString] -> CharString #
StringLike CharString # |
Methods toString :: CharString -> String # fromString :: String -> CharString # lines :: ListLike full CharString => CharString -> full # words :: ListLike full CharString => CharString -> full # unlines :: ListLike full CharString => full -> CharString # unwords :: ListLike full CharString => full -> CharString #
FoldableLL CharString Char # |
Methods foldl :: (a -> Char -> a) -> a -> CharString -> a # foldl' :: (a -> Char -> a) -> a -> CharString -> a # foldl1 :: (Char -> Char -> Char) -> CharString -> Char # foldr :: (Char -> b -> b) -> b -> CharString -> b # foldr' :: (Char -> b -> b) -> b -> CharString -> b # foldr1 :: (Char -> Char -> Char) -> CharString -> Char #
ListLike CharString Char # |
Methods empty :: CharString # singleton :: Char -> CharString # cons :: Char -> CharString -> CharString # snoc :: CharString -> Char -> CharString # append :: CharString -> CharString -> CharString # head :: CharString -> Char # uncons :: CharString -> Maybe (Char, CharString) # last :: CharString -> Char # tail :: CharString -> CharString # init :: CharString -> CharString # null :: CharString -> Bool # length :: CharString -> Int # map :: ListLike full' item' => (Char -> item') -> CharString -> full' # rigidMap :: (Char -> Char) -> CharString -> CharString # reverse :: CharString -> CharString # intersperse :: Char -> CharString -> CharString # concat :: (ListLike full' CharString, Monoid CharString) => full' -> CharString # concatMap :: ListLike full' item' => (Char -> full') -> CharString -> full' # rigidConcatMap :: (Char -> CharString) -> CharString -> CharString # any :: (Char -> Bool) -> CharString -> Bool # all :: (Char -> Bool) -> CharString -> Bool # maximum :: CharString -> Char # minimum :: CharString -> Char # replicate :: Int -> Char -> CharString # take :: Int -> CharString -> CharString # drop :: Int -> CharString -> CharString # splitAt :: Int -> CharString -> (CharString, CharString) # takeWhile :: (Char -> Bool) -> CharString -> CharString # dropWhile :: (Char -> Bool) -> CharString -> CharString # dropWhileEnd :: (Char -> Bool) -> CharString -> CharString # span :: (Char -> Bool) -> CharString -> (CharString, CharString) # break :: (Char -> Bool) -> CharString -> (CharString, CharString) # group :: (ListLike full' CharString, Eq Char) => CharString -> full' # inits :: ListLike full' CharString => CharString -> full' # tails :: ListLike full' CharString => CharString -> full' # isPrefixOf :: CharString -> CharString -> Bool # isSuffixOf :: CharString -> CharString -> Bool # isInfixOf :: CharString -> CharString -> Bool # stripPrefix :: CharString -> CharString -> Maybe CharString # stripSuffix :: CharString -> CharString -> Maybe CharString # elem :: Char -> CharString -> Bool # notElem :: Char -> CharString -> Bool # find :: (Char -> Bool) -> CharString -> Maybe Char # filter :: (Char -> Bool) -> CharString -> CharString # partition :: (Char -> Bool) -> CharString -> (CharString, CharString) # index :: CharString -> Int -> Char # elemIndex :: Char -> CharString -> Maybe Int # elemIndices :: (Eq Char, ListLike result Int) => Char -> CharString -> result # findIndex :: (Char -> Bool) -> CharString -> Maybe Int # findIndices :: ListLike result Int => (Char -> Bool) -> CharString -> result # sequence :: (Monad m, ListLike fullinp (m Char)) => fullinp -> m CharString # mapM :: (Monad m, ListLike full' item') => (Char -> m item') -> CharString -> m full' # rigidMapM :: Monad m => (Char -> m Char) -> CharString -> m CharString # nub :: CharString -> CharString # delete :: Char -> CharString -> CharString # deleteFirsts :: CharString -> CharString -> CharString # union :: CharString -> CharString -> CharString # intersect :: CharString -> CharString -> CharString # sort :: CharString -> CharString # insert :: Char -> CharString -> CharString # toList :: CharString -> [Char] # fromList :: [Char] -> CharString # fromListLike :: ListLike full' Char => CharString -> full' # nubBy :: (Char -> Char -> Bool) -> CharString -> CharString # deleteBy :: (Char -> Char -> Bool) -> Char -> CharString -> CharString # deleteFirstsBy :: (Char -> Char -> Bool) -> CharString -> CharString -> CharString # unionBy :: (Char -> Char -> Bool) -> CharString -> CharString -> CharString # intersectBy :: (Char -> Char -> Bool) -> CharString -> CharString -> CharString # groupBy :: (ListLike full' CharString, Eq Char) => (Char -> Char -> Bool) -> CharString -> full' # sortBy :: (Char -> Char -> Ordering) -> CharString -> CharString # insertBy :: (Char -> Char -> Ordering) -> Char -> CharString -> CharString # genericLength :: Num a => CharString -> a # genericTake :: Integral a => a -> CharString -> CharString # genericDrop :: Integral a => a -> CharString -> CharString # genericSplitAt :: Integral a => a -> CharString -> (CharString, CharString) # genericReplicate :: Integral a => a -> Char -> CharString #
ListLikeIO CharString Char # |
Methods hGetLine :: Handle -> IO CharString # hGetContents :: Handle -> IO CharString # hGet :: Handle -> Int -> IO CharString # hGetNonBlocking :: Handle -> Int -> IO CharString # hPutStr :: Handle -> CharString -> IO () # hPutStrLn :: Handle -> CharString -> IO () # getLine :: IO CharString # getContents :: IO CharString # putStr :: CharString -> IO () # putStrLn :: CharString -> IO () # interact :: (CharString -> CharString) -> IO () # readFile :: FilePath -> IO CharString # writeFile :: FilePath -> CharString -> IO () # appendFile :: FilePath -> CharString -> IO () #

newtype CharStringLazy #

Newtype wrapper around Data.ByteString.Lazy.Char8.ByteString, this allows for ListLike instances with Char elements.

Constructors

CSL |
Fields unCSL :: ByteString

Instances

Eq CharStringLazy # |
Methods (==) :: CharStringLazy -> CharStringLazy -> Bool # (/=) :: CharStringLazy -> CharStringLazy -> Bool #
Ord CharStringLazy # |
Methods compare :: CharStringLazy -> CharStringLazy -> Ordering # (<) :: CharStringLazy -> CharStringLazy -> Bool # (<=) :: CharStringLazy -> CharStringLazy -> Bool # (>) :: CharStringLazy -> CharStringLazy -> Bool # (>=) :: CharStringLazy -> CharStringLazy -> Bool # max :: CharStringLazy -> CharStringLazy -> CharStringLazy # min :: CharStringLazy -> CharStringLazy -> CharStringLazy #
Read CharStringLazy # |
Methods readsPrec :: Int -> ReadS CharStringLazy # readList :: ReadS [CharStringLazy] # readPrec :: ReadPrec CharStringLazy # readListPrec :: ReadPrec [CharStringLazy] #
Show CharStringLazy # |
Methods showsPrec :: Int -> CharStringLazy -> ShowS # show :: CharStringLazy -> String # showList :: [CharStringLazy] -> ShowS #
Monoid CharStringLazy # |
Methods mempty :: CharStringLazy # mappend :: CharStringLazy -> CharStringLazy -> CharStringLazy # mconcat :: [CharStringLazy] -> CharStringLazy #
StringLike CharStringLazy # |
Methods toString :: CharStringLazy -> String # fromString :: String -> CharStringLazy # lines :: ListLike full CharStringLazy => CharStringLazy -> full # words :: ListLike full CharStringLazy => CharStringLazy -> full # unlines :: ListLike full CharStringLazy => full -> CharStringLazy # unwords :: ListLike full CharStringLazy => full -> CharStringLazy #
FoldableLL CharStringLazy Char # |
Methods foldl :: (a -> Char -> a) -> a -> CharStringLazy -> a # foldl' :: (a -> Char -> a) -> a -> CharStringLazy -> a # foldl1 :: (Char -> Char -> Char) -> CharStringLazy -> Char # foldr :: (Char -> b -> b) -> b -> CharStringLazy -> b # foldr' :: (Char -> b -> b) -> b -> CharStringLazy -> b # foldr1 :: (Char -> Char -> Char) -> CharStringLazy -> Char #
ListLike CharStringLazy Char # |
Methods empty :: CharStringLazy # singleton :: Char -> CharStringLazy # cons :: Char -> CharStringLazy -> CharStringLazy # snoc :: CharStringLazy -> Char -> CharStringLazy # append :: CharStringLazy -> CharStringLazy -> CharStringLazy # head :: CharStringLazy -> Char # uncons :: CharStringLazy -> Maybe (Char, CharStringLazy) # last :: CharStringLazy -> Char # tail :: CharStringLazy -> CharStringLazy # init :: CharStringLazy -> CharStringLazy # null :: CharStringLazy -> Bool # length :: CharStringLazy -> Int # map :: ListLike full' item' => (Char -> item') -> CharStringLazy -> full' # rigidMap :: (Char -> Char) -> CharStringLazy -> CharStringLazy # reverse :: CharStringLazy -> CharStringLazy # intersperse :: Char -> CharStringLazy -> CharStringLazy # concat :: (ListLike full' CharStringLazy, Monoid CharStringLazy) => full' -> CharStringLazy # concatMap :: ListLike full' item' => (Char -> full') -> CharStringLazy -> full' # rigidConcatMap :: (Char -> CharStringLazy) -> CharStringLazy -> CharStringLazy # any :: (Char -> Bool) -> CharStringLazy -> Bool # all :: (Char -> Bool) -> CharStringLazy -> Bool # maximum :: CharStringLazy -> Char # minimum :: CharStringLazy -> Char # replicate :: Int -> Char -> CharStringLazy # take :: Int -> CharStringLazy -> CharStringLazy # drop :: Int -> CharStringLazy -> CharStringLazy # splitAt :: Int -> CharStringLazy -> (CharStringLazy, CharStringLazy) # takeWhile :: (Char -> Bool) -> CharStringLazy -> CharStringLazy # dropWhile :: (Char -> Bool) -> CharStringLazy -> CharStringLazy # dropWhileEnd :: (Char -> Bool) -> CharStringLazy -> CharStringLazy # span :: (Char -> Bool) -> CharStringLazy -> (CharStringLazy, CharStringLazy) # break :: (Char -> Bool) -> CharStringLazy -> (CharStringLazy, CharStringLazy) # group :: (ListLike full' CharStringLazy, Eq Char) => CharStringLazy -> full' # inits :: ListLike full' CharStringLazy => CharStringLazy -> full' # tails :: ListLike full' CharStringLazy => CharStringLazy -> full' # isPrefixOf :: CharStringLazy -> CharStringLazy -> Bool # isSuffixOf :: CharStringLazy -> CharStringLazy -> Bool # isInfixOf :: CharStringLazy -> CharStringLazy -> Bool # stripPrefix :: CharStringLazy -> CharStringLazy -> Maybe CharStringLazy # stripSuffix :: CharStringLazy -> CharStringLazy -> Maybe CharStringLazy # elem :: Char -> CharStringLazy -> Bool # notElem :: Char -> CharStringLazy -> Bool # find :: (Char -> Bool) -> CharStringLazy -> Maybe Char # filter :: (Char -> Bool) -> CharStringLazy -> CharStringLazy # partition :: (Char -> Bool) -> CharStringLazy -> (CharStringLazy, CharStringLazy) # index :: CharStringLazy -> Int -> Char # elemIndex :: Char -> CharStringLazy -> Maybe Int # elemIndices :: (Eq Char, ListLike result Int) => Char -> CharStringLazy -> result # findIndex :: (Char -> Bool) -> CharStringLazy -> Maybe Int # findIndices :: ListLike result Int => (Char -> Bool) -> CharStringLazy -> result # sequence :: (Monad m, ListLike fullinp (m Char)) => fullinp -> m CharStringLazy # mapM :: (Monad m, ListLike full' item') => (Char -> m item') -> CharStringLazy -> m full' # rigidMapM :: Monad m => (Char -> m Char) -> CharStringLazy -> m CharStringLazy # nub :: CharStringLazy -> CharStringLazy # delete :: Char -> CharStringLazy -> CharStringLazy # deleteFirsts :: CharStringLazy -> CharStringLazy -> CharStringLazy # union :: CharStringLazy -> CharStringLazy -> CharStringLazy # intersect :: CharStringLazy -> CharStringLazy -> CharStringLazy # sort :: CharStringLazy -> CharStringLazy # insert :: Char -> CharStringLazy -> CharStringLazy # toList :: CharStringLazy -> [Char] # fromList :: [Char] -> CharStringLazy # fromListLike :: ListLike full' Char => CharStringLazy -> full' # nubBy :: (Char -> Char -> Bool) -> CharStringLazy -> CharStringLazy # deleteBy :: (Char -> Char -> Bool) -> Char -> CharStringLazy -> CharStringLazy # deleteFirstsBy :: (Char -> Char -> Bool) -> CharStringLazy -> CharStringLazy -> CharStringLazy # unionBy :: (Char -> Char -> Bool) -> CharStringLazy -> CharStringLazy -> CharStringLazy # intersectBy :: (Char -> Char -> Bool) -> CharStringLazy -> CharStringLazy -> CharStringLazy # groupBy :: (ListLike full' CharStringLazy, Eq Char) => (Char -> Char -> Bool) -> CharStringLazy -> full' # sortBy :: (Char -> Char -> Ordering) -> CharStringLazy -> CharStringLazy # insertBy :: (Char -> Char -> Ordering) -> Char -> CharStringLazy -> CharStringLazy # genericLength :: Num a => CharStringLazy -> a # genericTake :: Integral a => a -> CharStringLazy -> CharStringLazy # genericDrop :: Integral a => a -> CharStringLazy -> CharStringLazy # genericSplitAt :: Integral a => a -> CharStringLazy -> (CharStringLazy, CharStringLazy) # genericReplicate :: Integral a => a -> Char -> CharStringLazy #
ListLikeIO CharStringLazy Char # |
Methods hGetLine :: Handle -> IO CharStringLazy # hGetContents :: Handle -> IO CharStringLazy # hGet :: Handle -> Int -> IO CharStringLazy # hGetNonBlocking :: Handle -> Int -> IO CharStringLazy # hPutStr :: Handle -> CharStringLazy -> IO () # hPutStrLn :: Handle -> CharStringLazy -> IO () # getLine :: IO CharStringLazy # getContents :: IO CharStringLazy # putStr :: CharStringLazy -> IO () # putStrLn :: CharStringLazy -> IO () # interact :: (CharStringLazy -> CharStringLazy) -> IO () # readFile :: FilePath -> IO CharStringLazy # writeFile :: FilePath -> CharStringLazy -> IO () # appendFile :: FilePath -> CharStringLazy -> IO () #

# Base Typeclasses

## The ListLike class

class (FoldableLL full item, Monoid full) => ListLike full item | full -> item where #

The class implementing list-like functions.

It is worth noting that types such as `Map` can be instances of `ListLike`. Due to their specific ways of operating, they may not behave in the expected way in some cases. For instance, `cons` may not increase the size of a map if the key you have given is already in the map; it will just replace the value already there.

Implementators must define at least:

- singleton
- head
- tail
- null or genericLength

Minimal complete definition

singleton, uncons, null | singleton, uncons, genericLength | singleton, head, tail, null | singleton, head, tail, genericLength

Methods

empty :: full #

The empty list

singleton :: item -> full #

Creates a single-element list out of an element

cons :: item -> full -> full #

Like (:) for lists: adds an element to the beginning of a list

snoc :: full -> item -> full #

Adds an element to the *end* of a `ListLike`.

append :: full -> full -> full #

Combines two lists. Like (++).

head :: full -> item #

Extracts the first element of a `ListLike`.

uncons :: full -> Maybe (item, full) #

Extract head and tail, return Nothing if empty

last :: full -> item #

Extracts the last element of a `ListLike`.

tail :: full -> full #

Gives all elements after the head.

init :: full -> full #

All elements of the list except the last one. See also `inits`.

null :: full -> Bool #

Tests whether the list is empty.

length :: full -> Int #

Length of the list. See also `genericLength`.

map :: ListLike full' item' => (item -> item') -> full -> full' #

Apply a function to each element, returning any other valid `ListLike`. `rigidMap` will always be at least as fast, if not faster, than this function and is recommended if it will work for your purposes. See also `mapM`.

rigidMap :: (item -> item) -> full -> full #

Like `map`, but without the possibility of changing the type of the item. This can have performance benefits for things such as ByteStrings, since it will let the ByteString use its native low-level map implementation.

reverse :: full -> full #

Reverse the elements in a list.

intersperse :: item -> full -> full #

Add an item between each element in the structure

concat :: (ListLike full' full, Monoid full) => full' -> full #

Flatten the structure.

concatMap :: ListLike full' item' => (item -> full') -> full -> full' #

Map a function over the items and concatenate the results. See also `rigidConcatMap`.

rigidConcatMap :: (item -> full) -> full -> full #

Like `concatMap`, but without the possibility of changing the type of the item. This can have performance benefits for some things such as ByteString.

any :: (item -> Bool) -> full -> Bool #

True if any items satisfy the function

all :: (item -> Bool) -> full -> Bool #

True if all items satisfy the function

maximum :: Ord item => full -> item #

The maximum value of the list

minimum :: Ord item => full -> item #

The minimum value of the list

replicate :: Int -> item -> full #

Generate a structure with the specified length with every element set to the item passed in. See also `genericReplicate`

take :: Int -> full -> full #

Takes the first n elements of the list. See also `genericTake`.

drop :: Int -> full -> full #

Drops the first n elements of the list. See also `genericDrop`

splitAt :: Int -> full -> (full, full) #

Equivalent to `(`take` n xs, `drop` n xs)`. See also `genericSplitAt`.

takeWhile :: (item -> Bool) -> full -> full #

Returns all elements at start of list that satisfy the function.

dropWhile :: (item -> Bool) -> full -> full #

Drops all elements from the start of the list that satisfy the function.

dropWhileEnd :: (item -> Bool) -> full -> full #

Drops all elements from the end of the list that satisfy the function.

span :: (item -> Bool) -> full -> (full, full) #

The equivalent of `(`takeWhile` f xs, `dropWhile` f xs)`

break :: (item -> Bool) -> full -> (full, full) #

The equivalent of ``span` (`not` . f)`

group :: (ListLike full' full, Eq item) => full -> full' #

Split a list into sublists, each which contains equal arguments. For order-preserving types, concatenating these sublists will produce the original list. See also `groupBy`.

inits :: ListLike full' full => full -> full' #

All initial segments of the list, shortest first

tails :: ListLike full' full => full -> full' #

All final segnemts, longest first

isPrefixOf :: Eq item => full -> full -> Bool #

True when the first list is at the beginning of the second.

isSuffixOf :: Eq item => full -> full -> Bool #

True when the first list is at the beginning of the second.

isInfixOf :: Eq item => full -> full -> Bool #

True when the first list is wholly containted within the second

stripPrefix :: Eq item => full -> full -> Maybe full #

Remove a prefix from a listlike if possible

stripSuffix :: Eq item => full -> full -> Maybe full #

Remove a suffix from a listlike if possible

elem :: Eq item => item -> full -> Bool #

True if the item occurs in the list

notElem :: Eq item => item -> full -> Bool #

True if the item does not occur in the list

find :: (item -> Bool) -> full -> Maybe item #

Take a function and return the first matching element, or Nothing if there is no such element.

filter :: (item -> Bool) -> full -> full #

Returns only the elements that satisfy the function.

partition :: (item -> Bool) -> full -> (full, full) #

Returns the lists that do and do not satisfy the function. Same as `(`filter` p xs, `filter` (`not` . p) xs)`

index :: full -> Int -> item #

The element at 0-based index i. Raises an exception if i is out of bounds. Like (!!) for lists.

elemIndex :: Eq item => item -> full -> Maybe Int #

Returns the index of the element, if it exists.

elemIndices :: (Eq item, ListLike result Int) => item -> full -> result #

Returns the indices of the matching elements. See also `findIndices`

findIndex :: (item -> Bool) -> full -> Maybe Int #

Take a function and return the index of the first matching element, or Nothing if no element matches

findIndices :: ListLike result Int => (item -> Bool) -> full -> result #

Returns the indices of all elements satisfying the function

sequence :: (Monad m, ListLike fullinp (m item)) => fullinp -> m full #

Evaluate each action in the sequence and collect the results

mapM :: (Monad m, ListLike full' item') => (item -> m item') -> full -> m full' #

A map in monad space. Same as ``sequence` . `map``

See also `rigidMapM`

rigidMapM :: Monad m => (item -> m item) -> full -> m full #

Like `mapM`, but without the possibility of changing the type of the item. This can have performance benefits with some types.

nub :: Eq item => full -> full #

Removes duplicate elements from the list. See also `nubBy`

delete :: Eq item => item -> full -> full #

Removes the first instance of the element from the list. See also `deleteBy`

deleteFirsts :: Eq item => full -> full -> full #

List difference. Removes from the first list the first instance of each element of the second list. See '(\)' and `deleteFirstsBy`

union :: Eq item => full -> full -> full #

List union: the set of elements that occur in either list. Duplicate elements in the first list will remain duplicate. See also `unionBy`.

intersect :: Eq item => full -> full -> full #

List intersection: the set of elements that occur in both lists. See also `intersectBy`

sort :: Ord item => full -> full #

Sorts the list. On data types that do not preserve ordering, or enforce their own ordering, the result may not be what you expect. See also `sortBy`.

insert :: Ord item => item -> full -> full #

Inserts the element at the last place where it is still less than or equal to the next element. On data types that do not preserve ordering, or enforce their own ordering, the result may not be what you expect. On types such as maps, this may result in changing an existing item. See also `insertBy`.

toList :: full -> [item] #

Converts the structure to a list. This is logically equivolent to `fromListLike`, but may have a more optimized implementation.

fromList :: [item] -> full #

Generates the structure from a list.

fromListLike :: ListLike full' item => full -> full' #

Converts one ListLike to another. See also `toList`. Default implementation is `fromListLike = map id`

nubBy :: (item -> item -> Bool) -> full -> full #

Generic version of `nub`

deleteBy :: (item -> item -> Bool) -> item -> full -> full #

Generic version of `deleteBy`

deleteFirstsBy :: (item -> item -> Bool) -> full -> full -> full #

Generic version of `deleteFirsts`

unionBy :: (item -> item -> Bool) -> full -> full -> full #

Generic version of `union`

intersectBy :: (item -> item -> Bool) -> full -> full -> full #

Generic version of `intersect`

groupBy :: (ListLike full' full, Eq item) => (item -> item -> Bool) -> full -> full' #

Generic version of `group`.

sortBy :: (item -> item -> Ordering) -> full -> full #

Sort function taking a custom comparison function

insertBy :: (item -> item -> Ordering) -> item -> full -> full #

Like `insert`, but with a custom comparison function

genericLength :: Num a => full -> a #

Length of the list

genericTake :: Integral a => a -> full -> full #

Generic version of `take`

genericDrop :: Integral a => a -> full -> full #

Generic version of `drop`

genericSplitAt :: Integral a => a -> full -> (full, full) #

Generic version of `splitAt`

genericReplicate :: Integral a => a -> item -> full #

Generic version of `replicate`

Instances

ListLike CharStringLazy Char # |
Methods empty :: CharStringLazy # singleton :: Char -> CharStringLazy # cons :: Char -> CharStringLazy -> CharStringLazy # snoc :: CharStringLazy -> Char -> CharStringLazy # append :: CharStringLazy -> CharStringLazy -> CharStringLazy # head :: CharStringLazy -> Char # uncons :: CharStringLazy -> Maybe (Char, CharStringLazy) # last :: CharStringLazy -> Char # tail :: CharStringLazy -> CharStringLazy # init :: CharStringLazy -> CharStringLazy # null :: CharStringLazy -> Bool # length :: CharStringLazy -> Int # map :: ListLike full' item' => (Char -> item') -> CharStringLazy -> full' # rigidMap :: (Char -> Char) -> CharStringLazy -> CharStringLazy # reverse :: CharStringLazy -> CharStringLazy # intersperse :: Char -> CharStringLazy -> CharStringLazy # concat :: (ListLike full' CharStringLazy, Monoid CharStringLazy) => full' -> CharStringLazy # concatMap :: ListLike full' item' => (Char -> full') -> CharStringLazy -> full' # rigidConcatMap :: (Char -> CharStringLazy) -> CharStringLazy -> CharStringLazy # any :: (Char -> Bool) -> CharStringLazy -> Bool # all :: (Char -> Bool) -> CharStringLazy -> Bool # maximum :: CharStringLazy -> Char # minimum :: CharStringLazy -> Char # replicate :: Int -> Char -> CharStringLazy # take :: Int -> CharStringLazy -> CharStringLazy # drop :: Int -> CharStringLazy -> CharStringLazy # splitAt :: Int -> CharStringLazy -> (CharStringLazy, CharStringLazy) # takeWhile :: (Char -> Bool) -> CharStringLazy -> CharStringLazy # dropWhile :: (Char -> Bool) -> CharStringLazy -> CharStringLazy # dropWhileEnd :: (Char -> Bool) -> CharStringLazy -> CharStringLazy # span :: (Char -> Bool) -> CharStringLazy -> (CharStringLazy, CharStringLazy) # break :: (Char -> Bool) -> CharStringLazy -> (CharStringLazy, CharStringLazy) # group :: (ListLike full' CharStringLazy, Eq Char) => CharStringLazy -> full' # inits :: ListLike full' CharStringLazy => CharStringLazy -> full' # tails :: ListLike full' CharStringLazy => CharStringLazy -> full' # isPrefixOf :: CharStringLazy -> CharStringLazy -> Bool # isSuffixOf :: CharStringLazy -> CharStringLazy -> Bool # isInfixOf :: CharStringLazy -> CharStringLazy -> Bool # stripPrefix :: CharStringLazy -> CharStringLazy -> Maybe CharStringLazy # stripSuffix :: CharStringLazy -> CharStringLazy -> Maybe CharStringLazy # elem :: Char -> CharStringLazy -> Bool # notElem :: Char -> CharStringLazy -> Bool # find :: (Char -> Bool) -> CharStringLazy -> Maybe Char # filter :: (Char -> Bool) -> CharStringLazy -> CharStringLazy # partition :: (Char -> Bool) -> CharStringLazy -> (CharStringLazy, CharStringLazy) # index :: CharStringLazy -> Int -> Char # elemIndex :: Char -> CharStringLazy -> Maybe Int # elemIndices :: (Eq Char, ListLike result Int) => Char -> CharStringLazy -> result # findIndex :: (Char -> Bool) -> CharStringLazy -> Maybe Int # findIndices :: ListLike result Int => (Char -> Bool) -> CharStringLazy -> result # sequence :: (Monad m, ListLike fullinp (m Char)) => fullinp -> m CharStringLazy # mapM :: (Monad m, ListLike full' item') => (Char -> m item') -> CharStringLazy -> m full' # rigidMapM :: Monad m => (Char -> m Char) -> CharStringLazy -> m CharStringLazy # nub :: CharStringLazy -> CharStringLazy # delete :: Char -> CharStringLazy -> CharStringLazy # deleteFirsts :: CharStringLazy -> CharStringLazy -> CharStringLazy # union :: CharStringLazy -> CharStringLazy -> CharStringLazy # intersect :: CharStringLazy -> CharStringLazy -> CharStringLazy # sort :: CharStringLazy -> CharStringLazy # insert :: Char -> CharStringLazy -> CharStringLazy # toList :: CharStringLazy -> [Char] # fromList :: [Char] -> CharStringLazy # fromListLike :: ListLike full' Char => CharStringLazy -> full' # nubBy :: (Char -> Char -> Bool) -> CharStringLazy -> CharStringLazy # deleteBy :: (Char -> Char -> Bool) -> Char -> CharStringLazy -> CharStringLazy # deleteFirstsBy :: (Char -> Char -> Bool) -> CharStringLazy -> CharStringLazy -> CharStringLazy # unionBy :: (Char -> Char -> Bool) -> CharStringLazy -> CharStringLazy -> CharStringLazy # intersectBy :: (Char -> Char -> Bool) -> CharStringLazy -> CharStringLazy -> CharStringLazy # groupBy :: (ListLike full' CharStringLazy, Eq Char) => (Char -> Char -> Bool) -> CharStringLazy -> full' # sortBy :: (Char -> Char -> Ordering) -> CharStringLazy -> CharStringLazy # insertBy :: (Char -> Char -> Ordering) -> Char -> CharStringLazy -> CharStringLazy # genericLength :: Num a => CharStringLazy -> a # genericTake :: Integral a => a -> CharStringLazy -> CharStringLazy # genericDrop :: Integral a => a -> CharStringLazy -> CharStringLazy # genericSplitAt :: Integral a => a -> CharStringLazy -> (CharStringLazy, CharStringLazy) # genericReplicate :: Integral a => a -> Char -> CharStringLazy #
ListLike CharString Char # |
Methods empty :: CharString # singleton :: Char -> CharString # cons :: Char -> CharString -> CharString # snoc :: CharString -> Char -> CharString # append :: CharString -> CharString -> CharString # head :: CharString -> Char # uncons :: CharString -> Maybe (Char, CharString) # last :: CharString -> Char # tail :: CharString -> CharString # init :: CharString -> CharString # null :: CharString -> Bool # length :: CharString -> Int # map :: ListLike full' item' => (Char -> item') -> CharString -> full' # rigidMap :: (Char -> Char) -> CharString -> CharString # reverse :: CharString -> CharString # intersperse :: Char -> CharString -> CharString # concat :: (ListLike full' CharString, Monoid CharString) => full' -> CharString # concatMap :: ListLike full' item' => (Char -> full') -> CharString -> full' # rigidConcatMap :: (Char -> CharString) -> CharString -> CharString # any :: (Char -> Bool) -> CharString -> Bool # all :: (Char -> Bool) -> CharString -> Bool # maximum :: CharString -> Char # minimum :: CharString -> Char # replicate :: Int -> Char -> CharString # take :: Int -> CharString -> CharString # drop :: Int -> CharString -> CharString # splitAt :: Int -> CharString -> (CharString, CharString) # takeWhile :: (Char -> Bool) -> CharString -> CharString # dropWhile :: (Char -> Bool) -> CharString -> CharString # dropWhileEnd :: (Char -> Bool) -> CharString -> CharString # span :: (Char -> Bool) -> CharString -> (CharString, CharString) # break :: (Char -> Bool) -> CharString -> (CharString, CharString) # group :: (ListLike full' CharString, Eq Char) => CharString -> full' # inits :: ListLike full' CharString => CharString -> full' # tails :: ListLike full' CharString => CharString -> full' # isPrefixOf :: CharString -> CharString -> Bool # isSuffixOf :: CharString -> CharString -> Bool # isInfixOf :: CharString -> CharString -> Bool # stripPrefix :: CharString -> CharString -> Maybe CharString # stripSuffix :: CharString -> CharString -> Maybe CharString # elem :: Char -> CharString -> Bool # notElem :: Char -> CharString -> Bool # find :: (Char -> Bool) -> CharString -> Maybe Char # filter :: (Char -> Bool) -> CharString -> CharString # partition :: (Char -> Bool) -> CharString -> (CharString, CharString) # index :: CharString -> Int -> Char # elemIndex :: Char -> CharString -> Maybe Int # elemIndices :: (Eq Char, ListLike result Int) => Char -> CharString -> result # findIndex :: (Char -> Bool) -> CharString -> Maybe Int # findIndices :: ListLike result Int => (Char -> Bool) -> CharString -> result # sequence :: (Monad m, ListLike fullinp (m Char)) => fullinp -> m CharString # mapM :: (Monad m, ListLike full' item') => (Char -> m item') -> CharString -> m full' # rigidMapM :: Monad m => (Char -> m Char) -> CharString -> m CharString # nub :: CharString -> CharString # delete :: Char -> CharString -> CharString # deleteFirsts :: CharString -> CharString -> CharString # union :: CharString -> CharString -> CharString # intersect :: CharString -> CharString -> CharString # sort :: CharString -> CharString # insert :: Char -> CharString -> CharString # toList :: CharString -> [Char] # fromList :: [Char] -> CharString # fromListLike :: ListLike full' Char => CharString -> full' # nubBy :: (Char -> Char -> Bool) -> CharString -> CharString # deleteBy :: (Char -> Char -> Bool) -> Char -> CharString -> CharString # deleteFirstsBy :: (Char -> Char -> Bool) -> CharString -> CharString -> CharString # unionBy :: (Char -> Char -> Bool) -> CharString -> CharString -> CharString # intersectBy :: (Char -> Char -> Bool) -> CharString -> CharString -> CharString # groupBy :: (ListLike full' CharString, Eq Char) => (Char -> Char -> Bool) -> CharString -> full' # sortBy :: (Char -> Char -> Ordering) -> CharString -> CharString # insertBy :: (Char -> Char -> Ordering) -> Char -> CharString -> CharString # genericLength :: Num a => CharString -> a # genericTake :: Integral a => a -> CharString -> CharString # genericDrop :: Integral a => a -> CharString -> CharString # genericSplitAt :: Integral a => a -> CharString -> (CharString, CharString) # genericReplicate :: Integral a => a -> Char -> CharString #
ListLike Chars Char # |
Methods empty :: Chars # singleton :: Char -> Chars # cons :: Char -> Chars -> Chars # snoc :: Chars -> Char -> Chars # append :: Chars -> Chars -> Chars # head :: Chars -> Char # uncons :: Chars -> Maybe (Char, Chars) # last :: Chars -> Char # tail :: Chars -> Chars # init :: Chars -> Chars # null :: Chars -> Bool # length :: Chars -> Int # map :: ListLike full' item' => (Char -> item') -> Chars -> full' # rigidMap :: (Char -> Char) -> Chars -> Chars # reverse :: Chars -> Chars # intersperse :: Char -> Chars -> Chars # concat :: (ListLike full' Chars, Monoid Chars) => full' -> Chars # concatMap :: ListLike full' item' => (Char -> full') -> Chars -> full' # rigidConcatMap :: (Char -> Chars) -> Chars -> Chars # any :: (Char -> Bool) -> Chars -> Bool # all :: (Char -> Bool) -> Chars -> Bool # maximum :: Chars -> Char # minimum :: Chars -> Char # replicate :: Int -> Char -> Chars # take :: Int -> Chars -> Chars # drop :: Int -> Chars -> Chars # splitAt :: Int -> Chars -> (Chars, Chars) # takeWhile :: (Char -> Bool) -> Chars -> Chars # dropWhile :: (Char -> Bool) -> Chars -> Chars # dropWhileEnd :: (Char -> Bool) -> Chars -> Chars # span :: (Char -> Bool) -> Chars -> (Chars, Chars) # break :: (Char -> Bool) -> Chars -> (Chars, Chars) # group :: (ListLike full' Chars, Eq Char) => Chars -> full' # inits :: ListLike full' Chars => Chars -> full' # tails :: ListLike full' Chars => Chars -> full' # isPrefixOf :: Chars -> Chars -> Bool # isSuffixOf :: Chars -> Chars -> Bool # isInfixOf :: Chars -> Chars -> Bool # stripPrefix :: Chars -> Chars -> Maybe Chars # stripSuffix :: Chars -> Chars -> Maybe Chars # elem :: Char -> Chars -> Bool # notElem :: Char -> Chars -> Bool # find :: (Char -> Bool) -> Chars -> Maybe Char # filter :: (Char -> Bool) -> Chars -> Chars # partition :: (Char -> Bool) -> Chars -> (Chars, Chars) # index :: Chars -> Int -> Char # elemIndex :: Char -> Chars -> Maybe Int # elemIndices :: (Eq Char, ListLike result Int) => Char -> Chars -> result # findIndex :: (Char -> Bool) -> Chars -> Maybe Int # findIndices :: ListLike result Int => (Char -> Bool) -> Chars -> result # sequence :: (Monad m, ListLike fullinp (m Char)) => fullinp -> m Chars # mapM :: (Monad m, ListLike full' item') => (Char -> m item') -> Chars -> m full' # rigidMapM :: Monad m => (Char -> m Char) -> Chars -> m Chars # nub :: Chars -> Chars # delete :: Char -> Chars -> Chars # deleteFirsts :: Chars -> Chars -> Chars # union :: Chars -> Chars -> Chars # intersect :: Chars -> Chars -> Chars # sort :: Chars -> Chars # insert :: Char -> Chars -> Chars # toList :: Chars -> [Char] # fromList :: [Char] -> Chars # fromListLike :: ListLike full' Char => Chars -> full' # nubBy :: (Char -> Char -> Bool) -> Chars -> Chars # deleteBy :: (Char -> Char -> Bool) -> Char -> Chars -> Chars # deleteFirstsBy :: (Char -> Char -> Bool) -> Chars -> Chars -> Chars # unionBy :: (Char -> Char -> Bool) -> Chars -> Chars -> Chars # intersectBy :: (Char -> Char -> Bool) -> Chars -> Chars -> Chars # groupBy :: (ListLike full' Chars, Eq Char) => (Char -> Char -> Bool) -> Chars -> full' # sortBy :: (Char -> Char -> Ordering) -> Chars -> Chars # insertBy :: (Char -> Char -> Ordering) -> Char -> Chars -> Chars # genericLength :: Num a => Chars -> a # genericTake :: Integral a => a -> Chars -> Chars # genericDrop :: Integral a => a -> Chars -> Chars # genericSplitAt :: Integral a => a -> Chars -> (Chars, Chars) # genericReplicate :: Integral a => a -> Char -> Chars #
ListLike [a] a # |
Methods empty :: [a] # singleton :: a -> [a] # cons :: a -> [a] -> [a] # snoc :: [a] -> a -> [a] # append :: [a] -> [a] -> [a] # head :: [a] -> a # uncons :: [a] -> Maybe (a, [a]) # last :: [a] -> a # tail :: [a] -> [a] # init :: [a] -> [a] # null :: [a] -> Bool # length :: [a] -> Int # map :: ListLike full' item' => (a -> item') -> [a] -> full' # rigidMap :: (a -> a) -> [a] -> [a] # reverse :: [a] -> [a] # intersperse :: a -> [a] -> [a] # concat :: (ListLike full' [a], Monoid [a]) => full' -> [a] # concatMap :: ListLike full' item' => (a -> full') -> [a] -> full' # rigidConcatMap :: (a -> [a]) -> [a] -> [a] # any :: (a -> Bool) -> [a] -> Bool # all :: (a -> Bool) -> [a] -> Bool # maximum :: [a] -> a # minimum :: [a] -> a # replicate :: Int -> a -> [a] # take :: Int -> [a] -> [a] # drop :: Int -> [a] -> [a] # splitAt :: Int -> [a] -> ([a], [a]) # takeWhile :: (a -> Bool) -> [a] -> [a] # dropWhile :: (a -> Bool) -> [a] -> [a] # dropWhileEnd :: (a -> Bool) -> [a] -> [a] # span :: (a -> Bool) -> [a] -> ([a], [a]) # break :: (a -> Bool) -> [a] -> ([a], [a]) # group :: (ListLike full' [a], Eq a) => [a] -> full' # inits :: ListLike full' [a] => [a] -> full' # tails :: ListLike full' [a] => [a] -> full' # isPrefixOf :: [a] -> [a] -> Bool # isSuffixOf :: [a] -> [a] -> Bool # isInfixOf :: [a] -> [a] -> Bool # stripPrefix :: [a] -> [a] -> Maybe [a] # stripSuffix :: [a] -> [a] -> Maybe [a] # elem :: a -> [a] -> Bool # notElem :: a -> [a] -> Bool # find :: (a -> Bool) -> [a] -> Maybe a # filter :: (a -> Bool) -> [a] -> [a] # partition :: (a -> Bool) -> [a] -> ([a], [a]) # index :: [a] -> Int -> a # elemIndex :: a -> [a] -> Maybe Int # elemIndices :: (Eq a, ListLike result Int) => a -> [a] -> result # findIndex :: (a -> Bool) -> [a] -> Maybe Int # findIndices :: ListLike result Int => (a -> Bool) -> [a] -> result # sequence :: (Monad m, ListLike fullinp (m a)) => fullinp -> m [a] # mapM :: (Monad m, ListLike full' item') => (a -> m item') -> [a] -> m full' # rigidMapM :: Monad m => (a -> m a) -> [a] -> m [a] # nub :: [a] -> [a] # delete :: a -> [a] -> [a] # deleteFirsts :: [a] -> [a] -> [a] # union :: [a] -> [a] -> [a] # intersect :: [a] -> [a] -> [a] # sort :: [a] -> [a] # insert :: a -> [a] -> [a] # toList :: [a] -> [a] # fromList :: [a] -> [a] # fromListLike :: ListLike full' a => [a] -> full' # nubBy :: (a -> a -> Bool) -> [a] -> [a] # deleteBy :: (a -> a -> Bool) -> a -> [a] -> [a] # deleteFirstsBy :: (a -> a -> Bool) -> [a] -> [a] -> [a] # unionBy :: (a -> a -> Bool) -> [a] -> [a] -> [a] # intersectBy :: (a -> a -> Bool) -> [a] -> [a] -> [a] # groupBy :: (ListLike full' [a], Eq a) => (a -> a -> Bool) -> [a] -> full' # sortBy :: (a -> a -> Ordering) -> [a] -> [a] # insertBy :: (a -> a -> Ordering) -> a -> [a] -> [a] # genericLength :: Num a => [a] -> a # genericTake :: Integral a => a -> [a] -> [a] # genericDrop :: Integral a => a -> [a] -> [a] # genericSplitAt :: Integral a => a -> [a] -> ([a], [a]) # genericReplicate :: Integral a => a -> a -> [a] #

## The FoldableLL class

class FoldableLL full item | full -> item where #

This is the primary class for structures that are to be considered foldable. A minimum complete definition provides `foldl` and `foldr`.

Instances of `FoldableLL` can be folded, and can be many and varied.

These functions are used heavily in Data.ListLike.

Minimal complete definition

foldl, foldr

Methods

foldl :: (a -> item -> a) -> a -> full -> a #

Left-associative fold

foldl' :: (a -> item -> a) -> a -> full -> a #

Strict version of `foldl`.

foldl1 :: (item -> item -> item) -> full -> item #

A variant of `foldl` with no base case. Requires at least 1 list element.

foldr :: (item -> b -> b) -> b -> full -> b #

Right-associative fold

foldr' :: (item -> b -> b) -> b -> full -> b #

Strict version of `foldr`

foldr1 :: (item -> item -> item) -> full -> item #

Like `foldr`, but with no starting value

Instances

FoldableLL CharStringLazy Char # |
Methods foldl :: (a -> Char -> a) -> a -> CharStringLazy -> a # foldl' :: (a -> Char -> a) -> a -> CharStringLazy -> a # foldl1 :: (Char -> Char -> Char) -> CharStringLazy -> Char # foldr :: (Char -> b -> b) -> b -> CharStringLazy -> b # foldr' :: (Char -> b -> b) -> b -> CharStringLazy -> b # foldr1 :: (Char -> Char -> Char) -> CharStringLazy -> Char #
FoldableLL CharString Char # |
Methods foldl :: (a -> Char -> a) -> a -> CharString -> a # foldl' :: (a -> Char -> a) -> a -> CharString -> a # foldl1 :: (Char -> Char -> Char) -> CharString -> Char # foldr :: (Char -> b -> b) -> b -> CharString -> b # foldr' :: (Char -> b -> b) -> b -> CharString -> b # foldr1 :: (Char -> Char -> Char) -> CharString -> Char #
FoldableLL Chars Char # |
Methods foldl :: (a -> Char -> a) -> a -> Chars -> a # foldl' :: (a -> Char -> a) -> a -> Chars -> a # foldl1 :: (Char -> Char -> Char) -> Chars -> Char # foldr :: (Char -> b -> b) -> b -> Chars -> b # foldr' :: (Char -> b -> b) -> b -> Chars -> b # foldr1 :: (Char -> Char -> Char) -> Chars -> Char #
FoldableLL [a] a # |
Methods foldl :: (a -> a -> a) -> a -> [a] -> a # foldl' :: (a -> a -> a) -> a -> [a] -> a # foldl1 :: (a -> a -> a) -> [a] -> a # foldr :: (a -> b -> b) -> b -> [a] -> b # foldr' :: (a -> b -> b) -> b -> [a] -> b # foldr1 :: (a -> a -> a) -> [a] -> a #

## The StringLike class

class StringLike s where #

An extension to `ListLike` for those data types that are similar to a `String`. Minimal complete definition is `toString` and `fromString`.

Minimal complete definition

toString, fromString

Methods

toString :: s -> String #

Converts the structure to a `String`

fromString :: String -> s #

Converts a `String` to a list

lines :: ListLike full s => s -> full #

Breaks a string into a list of strings

words :: ListLike full s => s -> full #

Breaks a string into a list of words

Instances

StringLike CharStringLazy # |
Methods toString :: CharStringLazy -> String # fromString :: String -> CharStringLazy # lines :: ListLike full CharStringLazy => CharStringLazy -> full # words :: ListLike full CharStringLazy => CharStringLazy -> full # unlines :: ListLike full CharStringLazy => full -> CharStringLazy # unwords :: ListLike full CharStringLazy => full -> CharStringLazy #
StringLike CharString # |
Methods toString :: CharString -> String # fromString :: String -> CharString # lines :: ListLike full CharString => CharString -> full # words :: ListLike full CharString => CharString -> full # unlines :: ListLike full CharString => full -> CharString # unwords :: ListLike full CharString => full -> CharString #
StringLike Chars # |
Methods toString :: Chars -> String # fromString :: String -> Chars # lines :: ListLike full Chars => Chars -> full # words :: ListLike full Chars => Chars -> full # unlines :: ListLike full Chars => full -> Chars # unwords :: ListLike full Chars => full -> Chars #

## The InfiniteListLike class

class ListLike full item => InfiniteListLike full item | full -> item where #

An extension to `ListLike` for those data types that are capable of dealing with infinite lists. Some `ListLike` functions are capable of working with finite or infinite lists. The functions here require infinite list capability in order to work at all.

Methods

iterate :: (item -> item) -> item -> full #

An infinite list of repeated calls of the function to args

repeat :: item -> full #

An infinite list where each element is the same

cycle :: full -> full #

Converts a finite list into a circular one