Operator alias for Data.FastVect.FastVect.cons (right-associative / precedence 6)
#Vect Sourcenewtype Vect :: Int -> Type -> Type
newtype 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 :: forall len elem. Reflectable len Int => Compare len NegOne GT => Proxy len -> elem -> Array elem -> Vect len elem
Creates 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 ]
#append Source
append :: forall m n m_plus_n elem. Append Vect m n m_plus_n elem
Append two Vect
s.
as :: Vect 300 String
as = replicate (Common.term :: _ 300) "a"
bs :: Vect 200 String
bs = replicate (Common.term :: _ 200) "b"
cs :: Vect 500 String
cs = append as bs
#cons Source
cons :: forall len len_plus_1 elem. Cons Vect len len_plus_1 elem
Attaches an element to the front of the Vect
, creating a new Vect
with size incremented.
Note, the running time of this function is O(n)
.
drop :: forall m n m_plus_n elem. Drop Vect m n m_plus_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 (Common.term :: _ 300) "a"
newVect :: Vect 200 String
newVect = drop (Common.term :: _ 100) vect
#empty Source
empty :: forall elem. Empty Vect elem
Creates the empty Vect
.
vect :: Vect 0 String
vect = empty
#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
#generate Source
generate :: forall len elem. Generate Vect len elem
Generate a Vect
of the given size by applying a function to each type level index.
head :: forall m elem. Head Vect m elem
Safely access the head of a Vect
.
vect :: Vect 300 String
vect = replicate (Common.term :: _ 300) "a"
elem :: String
elem = head vect
#last Source
last :: forall m elem. Last Vect m elem
Safely access the last element of a Vect
.
vect :: Vect 300 String
vect = replicate (Common.term :: _ 300) "a"
elem :: String
elem = last vect
#index Source
index :: forall m n elem. Index Vect m n elem
Safely access the i
-th element of a Vect
.
vect :: Vect 300 String
vect = replicate (Common.term :: _ 300) "a"
elem :: String
elem = index (Common.term :: _ 299) vect
#indexModulo Source
indexModulo :: forall m elem. IndexModulo Vect m elem
Safely 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
#modify Source
modify :: forall m n elem. Modify Vect m n elem
Safely modify element m
from a Vect
.
vect :: Vect 300 String
vect = replicate (Common.term :: _ 300) "a"
newVect :: Vect 100 String
newVect = modify (Common.term :: _ 100) (append "b") vect
#reifyVect Source
reifyVect :: forall elem r. Array elem -> (forall len. Vect len elem -> r) -> r
Applies a function to Array
that takes a Vector of arbitrary length.
replicate :: forall len elem. Replicate Vect len elem
Create a Vect
by replicating len
times the given element
vect :: Vect 300 String
vect = replicate (Common.term :: _ 300) "a"
#set Source
set :: forall m n elem. Set Vect m n elem
Safely set element m
from a Vect
.
vect :: Vect 300 String
vect = replicate (Common.term :: _ 300) "a"
newVect :: Vect 100 String
newVect = modify (Common.term :: _ 100) "b" vect
`
#snoc Source
snoc :: forall len len_plus_1 elem. Snoc Vect len len_plus_1 elem
Attaches an element to the end of the Vect
, creating a new Vect
with size incremented.
splitAt :: forall m n m_plus_n elem. SplitAt Vect m n m_plus_n elem
Split 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 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 (Common.term :: _ 300) "a"
newVect :: Vect 100 String
newVect = take (Common.term :: _ 100) vect
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4