W3cubDocs

/Haskell 8

Data.Containers.ListUtils

Copyright (c) Gershom Bazerman 2018
License BSD-style
Maintainer [email protected]
Portability portable
Safe Haskell Trustworthy
Language Haskell98

Description

This module provides efficient containers-based functions on the list type.

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

\( O(n \log n \). The nubOrd function removes duplicate elements from a list. In particular, it keeps only the first occurrence of each element. By using a Set internally it has better asymptotics than the standard nub function.

Strictness

nubOrd is strict in the elements of the list.

Efficiency note

When applicable, it is almost always better to use nubInt or nubIntOn instead of this function. For example, the best way to nub a list of characters is

 nubIntOn fromEnum xs

nubOrdOn :: Ord b => (a -> b) -> [a] -> [a] Source

The nubOrdOn function behaves just like nubOrd except it performs comparisons not on the original datatype, but a user-specified projection from that datatype.

Strictness

nubOrdOn is strict in the values of the function applied to the elements of the list.

nubInt :: [Int] -> [Int] Source

\( O(n \min(n,W)) \). The nubInt function removes duplicate Int values from a list. In particular, it keeps only the first occurrence of each element. By using an IntSet internally, it attains better asymptotics than the standard nub function.

See also nubIntOn, a more widely applicable generalization.

Strictness

nubInt is strict in the elements of the list.

nubIntOn :: (a -> Int) -> [a] -> [a] Source

The nubIntOn function behaves just like nubInt except it performs comparisons not on the original datatype, but a user-specified projection from that datatype.

Strictness

nubIntOn is strict in the values of the function applied to the elements of the list.

© The University of Glasgow and others
Licensed under a BSD-style license (see top of the page).
https://downloads.haskell.org/~ghc/8.6.1/docs/html/libraries/containers-0.6.0.1/Data-Containers-ListUtils.html