2021-05-20 13:55:22 +03:00
|
|
|
||| Additional functions about vectors
|
|
|
|
module Data.Vect.Extra
|
|
|
|
|
|
|
|
import Data.Vect
|
|
|
|
import Data.Fin
|
2021-05-24 10:48:00 +03:00
|
|
|
import Data.Vect.Elem
|
2021-05-20 13:55:22 +03:00
|
|
|
|
|
|
|
||| Version of `map` with access to the current position
|
|
|
|
public export
|
|
|
|
mapWithPos : (f : Fin n -> a -> b) -> Vect n a -> Vect n b
|
|
|
|
mapWithPos f [] = []
|
|
|
|
mapWithPos f (x :: xs) = f 0 x :: mapWithPos (f . FS) xs
|
2021-05-24 10:48:00 +03:00
|
|
|
|
|
|
|
||| Version of `map` with runtime-irrelevant information that the
|
|
|
|
||| argument is an element of the vector
|
|
|
|
public export
|
|
|
|
mapWithElem : (xs : Vect n a)
|
|
|
|
-> (f : (x : a) -> (0 pos : x `Elem` xs) -> b)
|
|
|
|
-> Vect n b
|
|
|
|
mapWithElem [] f = []
|
|
|
|
mapWithElem (x :: xs) f
|
|
|
|
= f x Here :: mapWithElem xs
|
|
|
|
(\x,pos => f x (There pos))
|