Module
Data.FastVect.Common
- Package
- purescript-fast-vect
- Repository
- sigma-andex/purescript-fast-vect
#Append Source
type Append :: forall k. (Int -> k -> Type) -> Int -> Int -> Int -> k -> Type
type Append vect m n m_plus_n elem = Add m n m_plus_n => Compare m NegOne GT => Reflectable m Int => Compare n NegOne GT => vect m elem -> vect n elem -> vect m_plus_n elem
Append two Vect
s.
as :: Vect 300 String
as = replicate (term :: _ 300) "a"
bs :: Vect 200 String
bs = replicate (term :: _ 200) "b"
cs :: Vect 500 String
cs = append as bs
#Drop Source
type Drop :: forall k. (Int -> k -> Type) -> Int -> Int -> Int -> k -> Type
type Drop vect m n m_plus_n elem = Add m n m_plus_n => Reflectable m Int => Compare m NegOne GT => Compare n NegOne GT => Proxy m -> vect m_plus_n elem -> vect n elem
Safely 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 (term :: _ 300) "a"
newVect :: Vect 200 String
newVect = drop (term :: _ 100) vect
#Index Source
type Index :: (Int -> Type -> Type) -> Int -> Int -> Type -> Type
type Index vect m n elem = Reflectable m Int => Compare m NegOne GT => Compare n NegOne GT => Compare m n LT => Proxy m -> vect n elem -> elem
Safely access the i
-th element of a Vect
.
vect :: Vect 300 String
vect = replicate (term :: _ 300) "a"
elem :: String
elem = index (term :: _ 299) vect
#IndexModulo Source
type IndexModulo :: (Int -> Type -> Type) -> Int -> Type -> Type
type IndexModulo vect m elem = Compare m Zero GT => Reflectable m Int => Int -> vect m elem -> elem
Safely access the n
-th modulo m element of a Vect
.
vect :: Vect 300 String
vect = replicate (term :: _ 300) "a"
elem :: String
elem = indexModulo 5352523 vect
#IndexModuloM Source
type IndexModuloM :: (Int -> Type -> Type) -> Int -> Type -> Type
type IndexModuloM vect m elem = Compare m Zero GT => Reflectable m Int => Int -> vect m elem -> Maybe elem
#Modify Source
type Modify :: (Int -> Type -> Type) -> Int -> Int -> Type -> Type
type Modify vect m n elem = Reflectable m Int => Compare m NegOne GT => Compare n NegOne GT => Compare m n LT => Proxy m -> (elem -> elem) -> vect n elem -> vect n elem
Safely modify element m
from a Vect
.
vect :: Vect 300 String
vect = replicate (term :: _ 300) "a"
newVect :: Vect 100 String
newVect = modify (term :: _ 100) (append "b") vect
#Set Source
type Set :: (Int -> Type -> Type) -> Int -> Int -> Type -> Type
type Set vect m n elem = Reflectable m Int => Compare m NegOne GT => Compare n NegOne GT => Compare m n LT => Proxy m -> elem -> vect n elem -> vect n elem
Safely set element m
from a Vect
.
vect :: Vect 300 String
vect = replicate (term :: _ 300) "a"
newVect :: Vect 100 String
newVect = modify (term :: _ 100) "b" vect
`
#Snoc Source
type Snoc :: (Int -> Type -> Type) -> Int -> Int -> Type -> Type
type Snoc vect len len_plus_1 elem = Add One len len_plus_1 => Reflectable len Int => Compare len NegOne GT => vect len elem -> elem -> vect len_plus_1 elem
Attaches an element to the end of the Vect
, creating a new Vect
with size incremented.
#SplitAt Source
type SplitAt :: forall k. (Int -> k -> Type) -> Int -> Int -> Int -> k -> Type
type SplitAt vect m n m_plus_n elem = Add m n m_plus_n => Reflectable m Int => Compare m NegOne GT => Compare n NegOne GT => Proxy m -> vect m_plus_n elem -> { after :: vect n elem, before :: vect m elem }
Split the Vect
into two sub vectors before
and after
, where before contains up to m
elements.
vect :: Vect 10 String
vect = replicate (term :: _ 10) "a"
split ::
{ after :: Vect 7 String
, before :: Vect 3 String
}
split = splitAt (term :: _ 3) vect
#Take Source
type Take :: forall k. (Int -> k -> Type) -> Int -> Int -> Int -> k -> Type
type Take vect m n m_plus_n elem = Add m n m_plus_n => Reflectable m Int => Compare m NegOne GT => Compare n NegOne GT => Proxy m -> vect m_plus_n elem -> vect m elem
Safely 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 (term :: _ 300) "a"
newVect :: Vect 100 String
newVect = take (term :: _ 100) vect
#IsVect Source
class IsVect :: (Type -> Type) -> Constraint
class (TraversableWithIndex Int f) <= IsVect f