Module

Data.Slice

Package
purescript-slice
Repository
jacereda/purescript-slices

A data type with O(1) take/drop using an array as the underlying storage.

#slice Source

slice :: forall a. Array a -> Slice a

#sarray Source

sarray :: forall a. Slice a -> Array a

#sempty Source

sempty :: forall a. Slice a

Constructor for the empty slice.

#sat Source

sat :: forall a. Slice a -> Int -> Maybe a

Access an element at an index.

#seq Source

seq :: forall a. Eq a => Slice a -> Slice a -> Boolean

Equality test.

#scompare Source

scompare :: forall a. Ord a => Slice a -> Slice a -> Ordering

Total order comparison.

#sdrop Source

sdrop :: forall a. Int -> Slice a -> Slice a

Drop a number of elements from the start of a slice, creating a new slice (O(1)).

#stake Source

stake :: forall a. Int -> Slice a -> Slice a

Keep only a number of elements from the start of a slice, creating a new slice (O(1)).

#shead Source

shead :: forall a. Slice a -> Maybe a

Get the first element in a slice, or Nothing if the slice is empty.

#slast Source

slast :: forall a. Slice a -> Maybe a

Get the last element in a slice, or Nothing if the slice is empty.

#sinit Source

sinit :: forall a. Slice a -> Maybe (Slice a)

Get all but the last element of a slice, creating a new slice, or Nothing if the slice is empty (O(1)).

#stail Source

stail :: forall a. Slice a -> Maybe (Slice a)

Get all but the first element of a slice, creating a new slice, or Nothing if the slice is empty (O(1)).

#snull Source

snull :: forall a. Slice a -> Boolean

Test whether a slice is empty.

#sappend Source

sappend :: forall a. Slice a -> Slice a -> Slice a

Concatenate two slices, creating a new slice.

#sconcat Source

sconcat :: forall a. Slice (Slice a) -> Slice a

Flatten a slice of slices, creating a new slice

#sconcatMap Source

sconcatMap :: forall b a. (a -> Slice b) -> Slice a -> Slice b

Apply a function to each element in an array, and flatten the results into a single, new array.

#sfind Source

sfind :: forall a. (a -> Boolean) -> Slice a -> Int

Find the first index for which a predicate holds, or -1 if no such element exists.

#sfindLast Source

sfindLast :: forall a. (a -> Boolean) -> Slice a -> Int

Find the last index for which a predicate holds, or -1 if no such element exists.

#smap Source

smap :: forall b a. (a -> b) -> Slice a -> Slice b

Apply a function to each element in a slice, creating a new slice.

#sfoldl Source

sfoldl :: forall b a. (b -> a -> b) -> b -> Slice a -> b

Apply a left-folding function to a slice.

#sfoldr Source

sfoldr :: forall b a. (a -> b -> b) -> b -> Slice a -> b

Apply a right-folding function to a slice.

#szipWith Source

szipWith :: forall c b a. (a -> b -> c) -> Slice a -> Slice b -> Slice c

Apply a function to pairs of elements at the same index in two slices, collecting the results in a new slice.

If one slice is longer, elements will be discarded from the longer slice.

For example

szipWith (*) (slice [1, 2, 3]) (slice [4, 5, 6, 7]) == slice [4, 10, 18]
Modules
Data.Slice