mirror of
https://github.com/idris-lang/Idris2.git
synced 2024-12-25 12:42:02 +03:00
24 lines
670 B
Idris
24 lines
670 B
Idris
||| Additional functions about vectors
|
|
module Data.Vect.Extra
|
|
|
|
import Data.Vect
|
|
import Data.Fin
|
|
import Data.Vect.Elem
|
|
|
|
||| 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
|
|
|
|
||| 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))
|