Module

Data.Array.NonEmpty

Package
purescript-arrays
Repository
purescript/purescript-arrays

#fromArray Source

fromArray :: forall a. Array a -> Maybe (NonEmptyArray a)

#fromNonEmpty Source

#toArray Source

toArray :: forall a. NonEmptyArray a -> Array a

#toNonEmpty Source

#fromFoldable Source

fromFoldable :: forall f a. Foldable f => f a -> Maybe (NonEmptyArray a)

#fromFoldable1 Source

fromFoldable1 :: forall f a. Foldable1 f => f a -> NonEmptyArray a

#toUnfoldable Source

toUnfoldable :: forall f a. Unfoldable f => NonEmptyArray a -> f a

#toUnfoldable1 Source

toUnfoldable1 :: forall f a. Unfoldable1 f => NonEmptyArray a -> f a

#singleton Source

singleton :: forall a. a -> NonEmptyArray a

#(..) Source

Operator alias for Data.Array.NonEmpty.range (non-associative / precedence 8)

#replicate Source

replicate :: forall a. Int -> a -> NonEmptyArray a

Replicate an item at least once

#some Source

some :: forall f a. Alternative f => Lazy (f (Array a)) => f a -> f (NonEmptyArray a)

#length Source

length :: forall a. NonEmptyArray a -> Int

#(:) Source

Operator alias for Data.Array.NonEmpty.cons (right-associative / precedence 6)

#cons Source

cons :: forall a. a -> NonEmptyArray a -> NonEmptyArray a

#cons' Source

cons' :: forall a. a -> Array a -> NonEmptyArray a

#snoc Source

snoc :: forall a. NonEmptyArray a -> a -> NonEmptyArray a

#snoc' Source

snoc' :: forall a. Array a -> a -> NonEmptyArray a

#appendArray Source

appendArray :: forall a. NonEmptyArray a -> Array a -> NonEmptyArray a

#insert Source

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

#insertBy Source

insertBy :: forall a. (a -> a -> Ordering) -> a -> NonEmptyArray a -> NonEmptyArray a

#head Source

head :: forall a. NonEmptyArray a -> a

#last Source

last :: forall a. NonEmptyArray a -> a

#tail Source

tail :: forall a. NonEmptyArray a -> Array a

#init Source

init :: forall a. NonEmptyArray a -> Array a

#uncons Source

uncons :: forall a. NonEmptyArray a -> { head :: a, tail :: Array a }

#unsnoc Source

unsnoc :: forall a. NonEmptyArray a -> { init :: Array a, last :: a }

#(!!) Source

Operator alias for Data.Array.NonEmpty.index (left-associative / precedence 8)

#index Source

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

#elem Source

elem :: forall a. Eq a => a -> NonEmptyArray a -> Boolean

#notElem Source

notElem :: forall a. Eq a => a -> NonEmptyArray a -> Boolean

#elemIndex Source

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

#elemLastIndex Source

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

#find Source

find :: forall a. (a -> Boolean) -> NonEmptyArray a -> Maybe a

#findMap Source

findMap :: forall a b. (a -> Maybe b) -> NonEmptyArray a -> Maybe b

#findIndex Source

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

#findLastIndex Source

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

#insertAt Source

insertAt :: forall a. Int -> a -> NonEmptyArray a -> Maybe (NonEmptyArray a)

#deleteAt Source

deleteAt :: forall a. Int -> NonEmptyArray a -> Maybe (Array a)

#updateAt Source

updateAt :: forall a. Int -> a -> NonEmptyArray a -> Maybe (NonEmptyArray a)

#updateAtIndices Source

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

#modifyAt Source

modifyAt :: forall a. Int -> (a -> a) -> NonEmptyArray a -> Maybe (NonEmptyArray a)

#modifyAtIndices Source

modifyAtIndices :: forall t a. Foldable t => t Int -> (a -> a) -> NonEmptyArray a -> NonEmptyArray a

#alterAt Source

alterAt :: forall a. Int -> (a -> Maybe a) -> NonEmptyArray a -> Maybe (Array a)

#intersperse Source

intersperse :: forall a. a -> NonEmptyArray a -> NonEmptyArray a

#reverse Source

reverse :: forall a. NonEmptyArray a -> NonEmptyArray a

#concatMap Source

concatMap :: forall a b. (a -> NonEmptyArray b) -> NonEmptyArray a -> NonEmptyArray b

#filter Source

filter :: forall a. (a -> Boolean) -> NonEmptyArray a -> Array a

#partition Source

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

#splitAt Source

splitAt :: forall a. Int -> NonEmptyArray a -> { after :: Array a, before :: Array a }

#filterA Source

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

#mapMaybe Source

mapMaybe :: forall a b. (a -> Maybe b) -> NonEmptyArray a -> Array b

#catMaybes Source

catMaybes :: forall a. NonEmptyArray (Maybe a) -> Array a

#mapWithIndex Source

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

#foldl1 Source

foldl1 :: forall a. (a -> a -> a) -> NonEmptyArray a -> a

#foldr1 Source

foldr1 :: forall a. (a -> a -> a) -> NonEmptyArray a -> a

#foldMap1 Source

foldMap1 :: forall a m. Semigroup m => (a -> m) -> NonEmptyArray a -> m

#fold1 Source

fold1 :: forall m. Semigroup m => NonEmptyArray m -> m

#intercalate Source

intercalate :: forall a. Semigroup a => a -> NonEmptyArray a -> a

#transpose Source

transpose :: forall a. NonEmptyArray (NonEmptyArray a) -> NonEmptyArray (NonEmptyArray a)

The 'transpose' function transposes the rows and columns of its argument. For example,

transpose 
  (NonEmptyArray [ NonEmptyArray [1, 2, 3]
                 , NonEmptyArray [4, 5, 6]
                 ]) == 
  (NonEmptyArray [ NonEmptyArray [1, 4]
                 , NonEmptyArray [2, 5]
                 , NonEmptyArray [3, 6]
                 ])

If some of the rows are shorter than the following rows, their elements are skipped:

transpose 
  (NonEmptyArray [ NonEmptyArray [10, 11]
                 , NonEmptyArray [20]
                 , NonEmptyArray [30, 31, 32]
                 ]) == 
  (NomEmptyArray [ NonEmptyArray [10, 20, 30]
                 , NonEmptyArray [11, 31]
                 , NonEmptyArray [32]
                 ])

#transpose' Source

transpose' :: forall a. NonEmptyArray (Array a) -> Maybe (NonEmptyArray (Array a))

transpose' is identical to transpose other than that the inner arrays are each a standard Array and not a NonEmptyArray. However, the result is wrapped in a Maybe to cater for the case where the inner Array is empty and must return Nothing.

#scanl Source

scanl :: forall a b. (b -> a -> b) -> b -> NonEmptyArray a -> NonEmptyArray b

#scanr Source

scanr :: forall a b. (a -> b -> b) -> b -> NonEmptyArray a -> NonEmptyArray b

#sort Source

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

#sortBy Source

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

#sortWith Source

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

#slice Source

slice :: forall a. Int -> Int -> NonEmptyArray a -> Array a

#take Source

take :: forall a. Int -> NonEmptyArray a -> Array a

#takeEnd Source

takeEnd :: forall a. Int -> NonEmptyArray a -> Array a

#takeWhile Source

takeWhile :: forall a. (a -> Boolean) -> NonEmptyArray a -> Array a

#drop Source

drop :: forall a. Int -> NonEmptyArray a -> Array a

#dropEnd Source

dropEnd :: forall a. Int -> NonEmptyArray a -> Array a

#dropWhile Source

dropWhile :: forall a. (a -> Boolean) -> NonEmptyArray a -> Array a

#span Source

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

#group Source

group :: forall a. Eq a => NonEmptyArray a -> NonEmptyArray (NonEmptyArray a)

Group equal, consecutive elements of an array into arrays.

group (NonEmptyArray [1, 1, 2, 2, 1]) ==
  NonEmptyArray [NonEmptyArray [1, 1], NonEmptyArray [2, 2], NonEmptyArray [1]]

#groupAll Source

groupAll :: forall a. Ord a => NonEmptyArray a -> NonEmptyArray (NonEmptyArray a)

Group equal elements of an array into arrays.

groupAll (NonEmptyArray [1, 1, 2, 2, 1]) ==
  NonEmptyArray [NonEmptyArray [1, 1, 1], NonEmptyArray [2, 2]]
`

#groupBy Source

groupBy :: forall a. (a -> a -> Boolean) -> NonEmptyArray a -> NonEmptyArray (NonEmptyArray a)

Group equal, consecutive elements of an array into arrays, using the specified equivalence relation to determine equality.

groupBy (\a b -> odd a && odd b) (NonEmptyArray [1, 3, 2, 4, 3, 3])
   = NonEmptyArray [NonEmptyArray [1, 3], NonEmptyArray [2], NonEmptyArray [4], NonEmptyArray [3, 3]]

#groupAllBy Source

groupAllBy :: forall a. (a -> a -> Ordering) -> NonEmptyArray a -> NonEmptyArray (NonEmptyArray a)

Group equal elements of an array into arrays, using the specified comparison function to determine equality.

groupAllBy (comparing Down) (NonEmptyArray [1, 3, 2, 4, 3, 3])
   = NonEmptyArray [NonEmptyArray [4], NonEmptyArray [3, 3, 3], NonEmptyArray [2], NonEmptyArray [1]]

#nub Source

nub :: forall a. Ord a => NonEmptyArray a -> NonEmptyArray a

#nubBy Source

nubBy :: forall a. (a -> a -> Ordering) -> NonEmptyArray a -> NonEmptyArray a

#nubEq Source

nubEq :: forall a. Eq a => NonEmptyArray a -> NonEmptyArray a

#nubByEq Source

nubByEq :: forall a. (a -> a -> Boolean) -> NonEmptyArray a -> NonEmptyArray a

#union Source

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

#union' Source

union' :: forall a. Eq a => NonEmptyArray a -> Array a -> NonEmptyArray a

#unionBy Source

unionBy :: forall a. (a -> a -> Boolean) -> NonEmptyArray a -> NonEmptyArray a -> NonEmptyArray a

#unionBy' Source

unionBy' :: forall a. (a -> a -> Boolean) -> NonEmptyArray a -> Array a -> NonEmptyArray a

#delete Source

delete :: forall a. Eq a => a -> NonEmptyArray a -> Array a

#deleteBy Source

deleteBy :: forall a. (a -> a -> Boolean) -> a -> NonEmptyArray a -> Array a

#(\\) Source

Operator alias for Data.Array.NonEmpty.difference (non-associative / precedence 5)

#difference Source

difference :: forall a. Eq a => NonEmptyArray a -> NonEmptyArray a -> Array a

#difference' Source

difference' :: forall a. Eq a => NonEmptyArray a -> Array a -> Array a

#intersect Source

intersect :: forall a. Eq a => NonEmptyArray a -> NonEmptyArray a -> Array a

#intersect' Source

intersect' :: forall a. Eq a => NonEmptyArray a -> Array a -> Array a

#intersectBy Source

intersectBy :: forall a. (a -> a -> Boolean) -> NonEmptyArray a -> NonEmptyArray a -> Array a

#intersectBy' Source

intersectBy' :: forall a. (a -> a -> Boolean) -> NonEmptyArray a -> Array a -> Array a

#zipWith Source

zipWith :: forall a b c. (a -> b -> c) -> NonEmptyArray a -> NonEmptyArray b -> NonEmptyArray c

#zipWithA Source

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

#zip Source

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

#unzip Source

unzip :: forall a b. NonEmptyArray (Tuple a b) -> Tuple (NonEmptyArray a) (NonEmptyArray b)

#any Source

any :: forall a. (a -> Boolean) -> NonEmptyArray a -> Boolean

#all Source

all :: forall a. (a -> Boolean) -> NonEmptyArray a -> Boolean

#foldM Source

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

#foldRecM Source

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

#unsafeIndex Source

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

Re-exports from Data.Array.NonEmpty.Internal

#NonEmptyArray Source

newtype NonEmptyArray a

An array that is known not to be empty.

You can use the constructor to create a NonEmptyArray that isn't non-empty, breaking the guarantee behind this newtype. It is provided as an escape hatch mainly for the Data.Array.NonEmpty and Data.Array modules. Use this at your own risk when you know what you are doing.

Instances