Package

purescript-slice

Repository
jacereda/purescript-slices
License
MIT
Uploaded by
jacereda
Published on
2017-04-11T20:31:45Z

Module Data.Slice

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

Slice

newtype Slice a

Represents a slice of an array.

slice

slice :: forall a. [a] -> Slice a

Create a slice from an array.

sarray

sarray :: forall a. Slice a -> [a]

Construct a new array from a slice.

sempty

sempty :: forall a. Slice a

Constructor for the empty slice.

sat

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

Access an element at an index.

seq

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

Equality test.

sdrop

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

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

stake

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

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

shead

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

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

slast

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

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

sinit

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

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

snull :: forall a. Slice a -> Boolean

Test whether a slice is empty.

sappend

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

Concatenate two slices, creating a new slice.

sconcat

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

Flatten a slice of slices, creating a new slice

sconcatMap

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

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

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

sfindLast

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

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

smap

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

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

sfoldl

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

Apply a left-folding function to a slice.

sfoldr

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

Apply a right-folding function to a slice.

szipWith

szipWith :: forall a b c. (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]

showSlice

instance showSlice :: (Show a) => Show (Slice a)

semigroupSlice

instance semigroupSlice :: Semigroup (Slice a)

monoidSlice

instance monoidSlice :: Monoid (Slice a)

foldableSlice

instance foldableSlice :: Foldable Slice

eqSlice

instance eqSlice :: (Eq a) => Eq (Slice a)

functorSlice

instance functorSlice :: Functor Slice

applySlice

instance applySlice :: Apply Slice

applicativeSlice

instance applicativeSlice :: Applicative Slice

bindSlice

instance bindSlice :: Bind Slice

monadSlice

instance monadSlice :: Monad Slice

altSlice

instance altSlice :: Alt Slice

plusSlice

instance plusSlice :: Plus Slice

alternativeSlice

instance alternativeSlice :: Alternative Slice

monadPlusSlice

instance monadPlusSlice :: MonadPlus Slice
Modules
Data.Slice
Dependencies