Module

Data.Set.Ordered

Package
purescript-ordered-set
Repository
flip111/purescript-ordered-set

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 Source

newtype OSet a

Instances

#fromFoldable Source

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

#toUnfoldable Source

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

#empty Source

empty :: forall a. OSet a

#isEmpty Source

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

#singleton Source

singleton :: forall a. a -> OSet a

#subset Source

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

#properSubset Source

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

#map Source

map :: forall b a. 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.

#(..) Source

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

#range Source

range :: Int -> Int -> OSet Int

#null Source

null :: forall a. OSet a -> Boolean

#length Source

length :: forall a. OSet a -> Int

#(:) Source

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

#cons Source

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

#snoc Source

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

#insert Source

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

#insertBy Source

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

#head Source

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

#last Source

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

#tail Source

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

#init Source

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

#uncons Source

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

#unsnoc Source

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

#(!!) Source

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

#index Source

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

#elemIndex Source

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

#elemLastIndex Source

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

#findIndex Source

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

#findLastIndex Source

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

#insertAt Source

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

#deleteAt Source

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

#updateAt Source

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

#updateAtIndices Source

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

#modifyAt Source

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

#alterAt Source

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

#reverse Source

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

#concat Source

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

#filter Source

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

#partition Source

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

#filterA Source

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

#mapMaybe Source

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

#catMaybes Source

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

#mapWithIndex Source

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

#sort Source

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

#sortBy Source

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

#sortWith Source

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

#slice Source

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

#take Source

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

#takeWhile Source

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

#drop Source

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

#dropWhile Source

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

#span Source

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

#union Source

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

#unionBy Source

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

#delete Source

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

#deleteWith Source

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

Delete first element matching the predicate.

#(\\) Source

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

#difference Source

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

#intersect Source

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

#intersectBy Source

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

#zipWith Source

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

#zipWithA Source

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

#zip Source

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

#unzip Source

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

#foldM Source

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

#foldRecM Source

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

#unsafeIndex Source

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

Re-exports from Data.Foldable

#foldMap Source

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

#foldl Source

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

#foldr Source

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

#notElem Source

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

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

#intercalate Source

intercalate :: forall m f. 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 Source

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

Fold a data structure, accumulating values in some Monoid.

#findMap Source

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

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

#find Source

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

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

#elem Source

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

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

#any Source

any :: forall f b a. 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 Source

all :: forall f b a. 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 Source

scanr :: forall f b a. 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 Source

scanl :: forall f b a. 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]