Data.FastVect.FastVect
- Package
- purescript-fast-vect
- Repository
- sigma-andex/purescript-fast-vect
#Vect Source
newtype Vect :: Int -> Type -> Typenewtype Vect len elem
A Vector: A list-like data structure that encodes it's length in the type, backed by an Array.
vect :: Vect 1 String
vect = singleton "a"
Instances
(Show elem, Reflectable len Int) => Show (Vect len elem)(Eq elem) => Eq (Vect len elem)(Ord elem) => Ord (Vect len elem)Functor (Vect len)Apply (Vect len)(Compare len NegOne GT, Reflectable len Int) => Applicative (Vect len)(Compare len NegOne GT, Reflectable len Int) => Bind (Vect len)(Compare len NegOne GT, Reflectable len Int) => Monad (Vect len)FunctorWithIndex Int (Vect len)Foldable (Vect len)FoldableWithIndex Int (Vect len)(Compare len Zero GT) => Foldable1 (Vect len)Traversable (Vect len)TraversableWithIndex Int (Vect len)(Compare len Zero GT) => Traversable1 (Vect len)(Compare len NegOne GT, Reflectable len Int) => Distributive (Vect len)(Semigroup a) => Semigroup (Vect len a)(Compare len NegOne GT, Reflectable len Int, Monoid a) => Monoid (Vect len a)(Compare len NegOne GT, Reflectable len Int, Semiring a) => Semiring (Vect len a)(Compare len NegOne GT, Reflectable len Int, Ring a) => Ring (Vect len a)(Compare len NegOne GT, Reflectable len Int, CommutativeRing a) => CommutativeRing (Vect len a)IsVect (Vect n)
#adjust Source
adjust :: forall len elem. Reflectable len Int => Compare len NegOne GT => Proxy len -> elem -> Array elem -> Vect len elemCreates a Vect by adjusting the given Array, padding with the provided element if the array is to small or dropping elements if the array is to big.
toArray $ adjust (Common.term :: _ 10) 0 [ 1, 2, 3 ] == [ 0, 0, 0, 0, 0, 0, 0, 1, 2, 3 ]
toArray $ adjust (Common.term :: _ 3) 0 [ 0, 0, 0, 0, 1, 2, 3 ] == [ 1, 2, 3 ]
#drop Source
drop :: forall m n m_plus_n elem. Drop Vect m n m_plus_n elemSafely drop m elements from a Vect.
Will result in a compile-time error if you are trying to drop more elements than exist in the vector.
vect :: Vect 300 String
vect = replicate (Common.term :: _ 300) "a"
newVect :: Vect 200 String
newVect = drop (Common.term :: _ 100) vect
#fromArray Source
fromArray :: forall len elem. Reflectable len Int => Compare len NegOne GT => Proxy len -> Array elem -> Maybe (Vect len elem)Attempt to create a Vect of a given size from an Array.
fromArray (Common.term :: _ 3) ["a", "b", "c"] = Just (Vect (Common.term :: _ 3) ["a", "b", "c"])
fromArray (Common.term :: _ 4) ["a", "b", "c"] = Nothing
#indexModulo Source
indexModulo :: forall m elem. IndexModulo Vect m elemSafely access the n-th modulo m element of a Vect.
vect :: Vect 300 String
vect = replicate (Common.term :: _ 300) "a"
elem :: String
elem = indexModulo 5352523 vect
#mapWithTerm Source
mapWithTerm :: forall len elem elem'. MapWithTerm Vect len elem elem'Map a function over a Vect with the type level index of each element.
#splitAt Source
splitAt :: forall m n m_plus_n elem. SplitAt Vect m n m_plus_n elemSplit the Vect into two sub vectors before and after, where before contains up to m elements.
vect :: Vect 10 String
vect = replicate (Common.term :: _ 10) "a"
split ::
{ after :: Vect 7 String
, before :: Vect 3 String
}
split = splitAt (Common.term :: _ 3) vect
#take Source
take :: forall m n m_plus_n elem. Take Vect m n m_plus_n elemSafely take m elements from a Vect.
Will result in a compile-time error if you are trying to take more elements than exist in the vector.
vect :: Vect 300 String
vect = replicate (Common.term :: _ 300) "a"
newVect :: Vect 100 String
newVect = take (Common.term :: _ 100) vect
#toNonEmptyArray Source
toNonEmptyArray :: forall len elem. Compare len Zero GT => Vect len elem -> NonEmptyArray elemConverts the Vect to an NonEmptyArray, dropping most of the size information.