summaryrefslogtreecommitdiff
path: root/src/Data/Vect/Properties/Insert.idr
blob: 28393b168c75aa3a42bec02bf6a4ee27477dc926 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
module Data.Vect.Properties.Insert

import Data.Vect

export
mapInsertAt :
  (0 f : a -> b) ->
  (i : Fin (S n)) ->
  (0 x : a) ->
  (xs : Vect n a) ->
  map f (insertAt i x xs) = insertAt i (f x) (map f xs)
mapInsertAt f FZ x xs = Refl
mapInsertAt f (FS i) x (y :: xs) = cong (f y ::) $ mapInsertAt f i x xs

export
indexInsertAt : (i : Fin (S n)) -> (0 x : a) -> (xs : Vect n a) -> index i (insertAt i x xs) = x
indexInsertAt FZ x xs = Refl
indexInsertAt (FS i) x (y :: xs) = indexInsertAt i x xs

export
insertAtIndex :
  (i : Fin (S n)) ->
  (xs : Vect (S n) a) ->
  insertAt i (index i xs) (deleteAt i xs) = xs
insertAtIndex FZ (x :: xs) = Refl
insertAtIndex (FS i) (x :: xs@(_ :: _)) = cong (x ::) $ insertAtIndex i xs