Module

Data.FastVect.MinLenVect

Package
purescript-fast-vect
Repository
sigma-andex/purescript-fast-vect

#(:) Source

Operator alias for Data.FastVect.MinLenVect.cons (right-associative / precedence 6)

#MinLenVect Source

newtype MinLenVect :: Int -> Type -> Typenewtype MinLenVect len elem

A Minimum Length Vector: A list-like data structure that encodes it's minimum length in the type, backed by an Array.

vect :: MinLenVect 1 String
vect = singleton "a"

Instances

#append Source

append :: forall m n m_plus_n elem. Append MinLenVect m n m_plus_n elem

Append two MinLenVects.

as :: MinLenVect 300 String
as = replicate (Common.term :: _ 300) "a"

bs :: MinLenVect 200 String
bs = replicate (Common.term :: _ 200) "b"

cs :: MinLenVect 500 String
cs = append as bs

#cons Source

cons :: forall len len_plus_1 elem. Cons MinLenVect len len_plus_1 elem

Attaches an element to the front of the MinLenVect, creating a new MinLenVect with minimum length incremented.

Note, the running time of this function is O(n).

#drop Source

drop :: forall m n m_plus_n elem. Drop MinLenVect m n m_plus_n elem

Safely drop m elements from a MinLenVect. Will result in a compile-time error if you are trying to drop more elements than exist in the minLenVector.

minLenVect :: MinLenVect 300 String
minLenVect = replicate (Common.term :: _ 300) "a"

newMinLenVect :: MinLenVect 200 String
newMinLenVect = drop (Common.term :: _ 100) minLenVect

#empty Source

empty :: forall elem. Empty MinLenVect elem

Creates the empty MinLenVect.

minLenVect :: MinLenVect 0 String
minLenVect = empty

#fromArray Source

fromArray :: forall len elem. Reflectable len Int => Compare len NegOne GT => Proxy len -> Array elem -> Maybe (MinLenVect len elem)

Attempt to create a MinLenVect of at least a given minimum length from an Array.

fromArray (Common.term :: _ 3) ["a", "b", "c"] = Just (MinLenVect (Common.term :: _ 3) ["a", "b", "c"])

fromArray (Common.term :: _ 3) ["a", "b", "c", "d", "e"] = Just (MinLenVect (Common.term :: _ 3) ["a", "b", "c", "d", "e"])

fromArray (Common.term :: _ 4) ["a", "b", "c"] = Nothing

#fromNonEmptyArray Source

fromNonEmptyArray :: forall len elem. Reflectable len Int => Compare len NegOne GT => Proxy len -> NonEmptyArray elem -> Maybe (MinLenVect len elem)

Attempt to create a MinLenVect of at least a given minimum length from a NonEmptyArray.

fromArray (Common.term :: _ 3) (cons' "a" ["b", "c"]) = Just (MinLenVect (Common.term :: _ 3) ["a", "b", "c"])

fromArray (Common.term :: _ 3) (cons' "a" ["b", "c", "d", "e"]) = Just (MinLenVect (Common.term :: _ 3) ["a", "b", "c", "d", "e"])

fromArray (Common.term :: _ 4) (cons' "a" ["b", "c"]) = Nothing

#fromUnsizedArray Source

fromUnsizedArray :: forall elem. Array elem -> MinLenVect 0 elem

Converts an Array to a MinLenVect of minimum length 0

#fromUnsizedNonEmptyArray Source

fromUnsizedNonEmptyArray :: forall elem. NonEmptyArray elem -> MinLenVect 1 elem

Converts a NonEmptyArray to a MinLenVect of minimum length 1

#generate Source

generate :: forall len elem. Generate MinLenVect len elem

Generate a MinLenVect of the given minimum length by applying a function to each type level index.

#head Source

head :: forall m elem. Head MinLenVect m elem

Safely access the head of a MinLenVect.

minLenVect :: MinLenVect 300 String
minLenVect = replicate (Common.term :: _ 300) "a"

elem :: String
elem = head minLenVect

#last Source

last :: forall m elem. Last MinLenVect m elem

Safely access the last element of a MinLenVect.

minLenVect :: MinLenVect 300 String
minLenVect = replicate (Common.term :: _ 300) "a"

elem :: String
elem = last minLenVect

#index Source

index :: forall m n elem. Index MinLenVect m n elem

Safely access the i-th element of a MinLenVect.

minLenVect :: MinLenVect 300 String
minLenVect = replicate (Common.term :: _ 300) "a"

elem :: String
elem = index (Common.term :: _ 299) minLenVect

#indexModulo Source

indexModulo :: forall m elem. IndexModulo MinLenVect m elem

Safely access the n-th modulo m element of a MinLenVect.

minLenVect :: MinLenVect 300 String
minLenVect = replicate (Common.term :: _ 300) "a"

elem :: String
elem = indexModulo 5352523 minLenVect

#mapWithTerm Source

mapWithTerm :: forall len elem elem'. MapWithTerm MinLenVect len elem elem'

Map a function over a MinLenVect with the type level index of each element.

#modify Source

modify :: forall m n elem. Modify MinLenVect m n elem

Safely modify element m from a MinLenVect.

minLenVect :: MinLenVect 300 String
minLenVect = replicate (Common.term :: _ 300) "a"

newMinLenVect :: MinLenVect 100 String
newMinLenVect = modify (Common.term :: _ 100) (append "b") minLenVect

#reifyMinLenVect Source

reifyMinLenVect :: forall elem r. Array elem -> (forall len. MinLenVect len elem -> r) -> r

Applies a function to Array that takes a MinLenVector of arbitrary minimum length.

#replicate Source

replicate :: forall len elem. Replicate MinLenVect len elem

Create a MinLenVect by replicating len times the given element

minLenVect :: MinLenVect 300 String
minLenVect = replicate (Common.term :: _ 300) "a"

#set Source

set :: forall m n elem. Set MinLenVect m n elem

Safely set element m from a MinLenVect.

minLenVect :: MinLenVect 300 String
minLenVect = replicate (Common.term :: _ 300) "a"

newMinLenVect :: MinLenVect 100 String
newMinLenVect = modify (Common.term :: _ 100) "b" minLenVect
`

#singleton Source

singleton :: forall elem. Singleton MinLenVect elem

Create a MinLenVect of one element.

minLenVect :: MinLenVect 1 String
minLenVect = singleton "a"

#snoc Source

snoc :: forall len len_plus_1 elem. Snoc MinLenVect len len_plus_1 elem

Attaches an element to the end of the MinLenVect, creating a new MinLenVect with minimum length incremented.

#splitAt Source

splitAt :: forall m n m_plus_n elem. SplitAt MinLenVect m n m_plus_n elem

Split the MinLenVect into two sub minLenVectors before and after, where before contains up to m elements.

minLenVect :: MinLenVect 10 String
minLenVect = replicate (Common.term :: _ 10) "a"

split ::
  { after :: MinLenVect 7 String
  , before :: MinLenVect 3 String
  }
split = splitAt (Common.term :: _ 3) minLenVect

#take Source

take :: forall m n m_plus_n elem. Take MinLenVect m n m_plus_n elem

Safely take m elements from a MinLenVect. Will result in a compile-time error if you are trying to take more elements than exist in the minLenVector.

minLenVect :: MinLenVect 300 String
minLenVect = replicate (Common.term :: _ 300) "a"

newMinLenVect :: MinLenVect 100 String
newMinLenVect = take (Common.term :: _ 100) minLenVect

#toArray Source

toArray :: forall len elem. Compare len NegOne GT => MinLenVect len elem -> Array elem

Converts the MinLenVect to an Array, effectively dropping the minimum length information.

#toNonEmptyArray Source

toNonEmptyArray :: forall len elem. Compare len Zero GT => MinLenVect len elem -> NonEmptyArray elem

Converts the MinLenVect to an NonEmptyArray, dropping most of the minimum length information.

#toVect Source

toVect :: forall len elem. Reflectable len Int => Compare len NegOne GT => Proxy len -> MinLenVect len elem -> Maybe (Vect len elem)

Attempt to create a Vect of the given length from a MinLenVect

#fromVect Source

fromVect :: forall len elem. Vect len elem -> MinLenVect len elem

Create a MinLenVect from a Vect