Community
Modules 31

Data.Containers.ListUtils

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

In the documentation, n is the number of elements in the list while d is the number of distinct elements in the list. W is the number of bits in an Int.

2 generation diagnostics
  • unattached documentation comment at 39:1
  • unattached documentation comment at 132:1

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

O(n \log d) . 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, although it can be a little worse in certain pathological cases. For example, to nub a list of characters, use

nubIntOn fromEnum xs

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

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]

O(n \min(d,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]

The nubIntOn function behaves just like nubInt except it performs comparisons not on the original datatype, but a user-specified projection from that datatype. For example, nubIntOn fromEnum can be used to nub characters and typical fixed-with numerical types efficiently.

Strictness

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

Maintainer
libraries@haskell.org
Portability
portable
Copyright
(c) Gershom Bazerman 2018
License
BSD-style
Build record and source files

Community contribution. The service has not verified this documentation. The generator reported 15 diagnostics.

Target: Linux on x86-64. Some inferred types and resolved links are not available.

Generator: aihc-haddock-aa6debbd-web-3

Metadata snapshot: 634f718c0d8cd970c4e2c511d2345d8fd36c6dc32b06343c2b4e914ffccbce7f

Open the dependency plan · Download the documentation model

Import a package

Enter a package name and an exact version from Hackage. The site contains imported versions only.