Module

Data.Set.Ordered

Like Data.Array but keeps unique values. Inspired by haskell's Data.Set.Ordered

Some of Data.Array's functions are not included because they don't make sense when there are already unique values: nub, nubEq, nubBy, replicate

For documentation of functions look in Data.Array

Help is appreciated for implementing the following functions and instances:

  • Functions: some, many, concatMap, group, group', groupBy, findMin, findMax, map
  • Instances: Apply, Bind, Traversable, Show, Ord, Monoid

#OSet

newtype OSet a

Instances

#fromFoldable

fromFoldable :: forall f. Foldable f => f ~> OSet

#toUnfoldable

toUnfoldable :: forall f. Unfoldable f => OSet ~> f

#empty

empty :: forall a. OSet a

#isEmpty

isEmpty :: forall a. Eq a => OSet a -> Boolean

#singleton

singleton :: forall a. a -> OSet a

#subset

subset :: forall a. Eq a => OSet a -> OSet a -> Boolean

#properSubset

properSubset :: forall a. Eq a => OSet a -> OSet a -> Boolean

#map

map :: forall a b. Ord b => (a -> b) -> OSet a -> OSet b

Maps over the values in a set.

This operation is not structure-preserving for sets, so is not a valid Functor. An example case: mapping const x over a set with n > 0 elements will result in a set with one element.

#(..)

Operator alias for Data.Set.Ordered.range (non-associative / precedence 8)

#range

range :: Int -> Int -> OSet Int

#null

null :: forall a. OSet a -> Boolean

#length

length :: forall a. OSet a -> Int

#(:)

Operator alias for Data.Set.Ordered.cons (right-associative / precedence 6)

#cons

cons :: forall a. Eq a => a -> OSet a -> OSet a

#snoc

snoc :: forall a. Eq a => OSet a -> a -> OSet a

#insert

insert :: forall a. Ord a => a -> OSet a -> OSet a

#insertBy

insertBy :: forall a. Eq a => (a -> a -> Ordering) -> a -> OSet a -> OSet a

#head

head :: forall a. OSet a -> Maybe a

#last

last :: forall a. OSet a -> Maybe a

#tail

tail :: forall a. OSet a -> Maybe (OSet a)

#init

init :: forall a. OSet a -> Maybe (OSet a)

#uncons

uncons :: forall a. OSet a -> Maybe { head :: a, tail :: OSet a }

#unsnoc

unsnoc :: forall a. OSet a -> Maybe { init :: OSet a, last :: a }

#(!!)

Operator alias for Data.Set.Ordered.index (left-associative / precedence 8)

#index

index :: forall a. OSet a -> Int -> Maybe a

#elemIndex

elemIndex :: forall a. Eq a => a -> OSet a -> Maybe Int

#elemLastIndex

elemLastIndex :: forall a. Eq a => a -> OSet a -> Maybe Int

#findIndex

findIndex :: forall a. (a -> Boolean) -> OSet a -> Maybe Int

#findLastIndex

findLastIndex :: forall a. (a -> Boolean) -> OSet a -> Maybe Int

#insertAt

insertAt :: forall a. Eq a => Int -> a -> OSet a -> Maybe (OSet a)

#deleteAt

deleteAt :: forall a. Int -> OSet a -> Maybe (OSet a)

#updateAt

updateAt :: forall a. Eq a => Int -> a -> OSet a -> Maybe (OSet a)

#updateAtIndices

updateAtIndices :: forall t a. Eq a => Foldable t => t (Tuple Int a) -> OSet a -> OSet a

#modifyAt

modifyAt :: forall a. Eq a => Int -> (a -> a) -> OSet a -> Maybe (OSet a)

#alterAt

alterAt :: forall a. Eq a => Int -> (a -> Maybe a) -> OSet a -> Maybe (OSet a)

#reverse

reverse :: forall a. OSet a -> OSet a

#concat

concat :: forall a. Eq a => OSet (OSet a) -> OSet a

#filter

filter :: forall a. (a -> Boolean) -> OSet a -> OSet a

#partition

partition :: forall a. (a -> Boolean) -> OSet a -> { no :: OSet a, yes :: OSet a }

#filterA

filterA :: forall a f. Applicative f => (a -> f Boolean) -> OSet a -> f (OSet a)

#mapMaybe

mapMaybe :: forall a b. (a -> Maybe b) -> OSet a -> OSet b

#catMaybes

catMaybes :: forall a. OSet (Maybe a) -> OSet a

#mapWithIndex

mapWithIndex :: forall a b. (Int -> a -> b) -> OSet a -> OSet b

#sort

sort :: forall a. Ord a => OSet a -> OSet a

#sortBy

sortBy :: forall a. (a -> a -> Ordering) -> OSet a -> OSet a

#sortWith

sortWith :: forall a b. Ord b => (a -> b) -> OSet a -> OSet a

#slice

slice :: forall a. Int -> Int -> OSet a -> OSet a

#take

take :: forall a. Int -> OSet a -> OSet a

#takeWhile

takeWhile :: forall a. (a -> Boolean) -> OSet a -> OSet a

#drop

drop :: forall a. Int -> OSet a -> OSet a

#dropWhile

dropWhile :: forall a. (a -> Boolean) -> OSet a -> OSet a

#span

span :: forall a. (a -> Boolean) -> OSet a -> { init :: OSet a, rest :: OSet a }

#union

union :: forall a. Eq a => OSet a -> OSet a -> OSet a

#unionBy

unionBy :: forall a. Eq a => (a -> a -> Boolean) -> OSet a -> OSet a -> OSet a

#delete

delete :: forall a. Eq a => a -> OSet a -> OSet a

#deleteWith

deleteWith :: forall a. (a -> Boolean) -> OSet a -> OSet a

Delete first element matching the predicate.

#(\\)

Operator alias for Data.Set.Ordered.difference (non-associative / precedence 5)

#difference

difference :: forall a. Eq a => OSet a -> OSet a -> OSet a

#intersect

intersect :: forall a. Eq a => OSet a -> OSet a -> OSet a

#intersectBy

intersectBy :: forall a. (a -> a -> Boolean) -> OSet a -> OSet a -> OSet a

#zipWith

zipWith :: forall a b c. Eq c => (a -> b -> c) -> OSet a -> OSet b -> OSet c

#zipWithA

zipWithA :: forall m a b c. Eq c => Applicative m => (a -> b -> m c) -> OSet a -> OSet b -> m (OSet c)

#zip

zip :: forall a b. OSet a -> OSet b -> OSet (Tuple a b)

#unzip

unzip :: forall a b. Eq a => Eq b => OSet (Tuple a b) -> Tuple (OSet a) (OSet b)

#foldM

foldM :: forall m a b. Monad m => (a -> b -> m a) -> a -> OSet b -> m a

#foldRecM

foldRecM :: forall m a b. MonadRec m => (a -> b -> m a) -> a -> OSet b -> m a

#unsafeIndex

unsafeIndex :: forall a. Partial => OSet a -> Int -> a

Re-exports from Data.Foldable

#foldMap

foldMap :: forall f a m. Foldable f => Monoid m => (a -> m) -> f a -> m

#foldl

foldl :: forall f a b. Foldable f => (b -> a -> b) -> b -> f a -> b

#foldr

foldr :: forall f a b. Foldable f => (a -> b -> b) -> b -> f a -> b

#notElem

notElem :: forall a f. Foldable f => Eq a => a -> f a -> Boolean

Test whether a value is not an element of a data structure.

#intercalate

intercalate :: forall f m. Foldable f => Monoid m => m -> f m -> m

Fold a data structure, accumulating values in some Monoid, combining adjacent elements using the specified separator.

For example:

> intercalate ", " ["Lorem", "ipsum", "dolor"]
= "Lorem, ipsum, dolor"

> intercalate "*" ["a", "b", "c"]
= "a*b*c"

> intercalate [1] [[2, 3], [4, 5], [6, 7]]
= [2, 3, 1, 4, 5, 1, 6, 7]

#fold

fold :: forall f m. Foldable f => Monoid m => f m -> m

Fold a data structure, accumulating values in some Monoid.

#findMap

findMap :: forall a b f. Foldable f => (a -> Maybe b) -> f a -> Maybe b

Try to find an element in a data structure which satisfies a predicate mapping.

#find

find :: forall a f. Foldable f => (a -> Boolean) -> f a -> Maybe a

Try to find an element in a data structure which satisfies a predicate.

#elem

elem :: forall a f. Foldable f => Eq a => a -> f a -> Boolean

Test whether a value is an element of a data structure.

#any

any :: forall a b f. Foldable f => HeytingAlgebra b => (a -> b) -> f a -> b

any f is the same as or <<< map f; map a function over the structure, and then get the disjunction of the results.

#all

all :: forall a b f. Foldable f => HeytingAlgebra b => (a -> b) -> f a -> b

all f is the same as and <<< map f; map a function over the structure, and then get the conjunction of the results.

Re-exports from Data.Traversable

#scanr

scanr :: forall a b f. Traversable f => (a -> b -> b) -> b -> f a -> f b

Fold a data structure from the right, keeping all intermediate results instead of only the final result. Note that the initial value does not appear in the result (unlike Haskell's Prelude.scanr).

scanr (+) 0 [1,2,3] = [6,5,3]
scanr (flip (-)) 10 [1,2,3] = [4,5,7]

#scanl

scanl :: forall a b f. Traversable f => (b -> a -> b) -> b -> f a -> f b

Fold a data structure from the left, keeping all intermediate results instead of only the final result. Note that the initial value does not appear in the result (unlike Haskell's Prelude.scanl).

scanl (+) 0  [1,2,3] = [1,3,6]
scanl (-) 10 [1,2,3] = [9,7,4]

Modules