17 | module Spidr.Data.List
19 | import public Data.DPair
20 | import public Data.List
21 | import public Data.List.Quantifiers
27 | range : (n : Nat) -> List Nat
29 | range (S n) = snoc (range n) n
34 | enumerate : List a -> List (Nat, a)
35 | enumerate xs = zip (range (length xs)) xs
41 | unique : Eq a => List a -> Bool
43 | unique (x :: xs) = not (elem x xs) && unique xs
49 | , unique [0, 1] = True
50 | , unique [1, 0] = True
51 | , unique [0, 0] = False
52 | , unique [0, 0, 1] = False
53 | , unique [0, 1, 0] = False
54 | , unique [1, 0, 0] = False
55 | , unique [1, 1, 0] = False
56 | , unique [1, 0, 1] = False
57 | , unique [0, 1, 1] = False
58 | , unique [1, 2, 3] = True
69 | (idxs : List Nat) ->
71 | {auto 0 inBounds : All (flip InBounds xs) idxs} ->
73 | multiIndex idxs xs = map (\(Element i ib) => index i xs) $
pushIn idxs inBounds
82 | (idxs : List Nat) ->
84 | {auto 0 inBounds : All (flip InBounds xs) idxs} ->
86 | deleteAt idxs xs = impl 0 xs
88 | impl : Nat -> List a -> List a
90 | impl i (x :: xs) = if elem i idxs then impl (S i) xs else x :: impl (S i) xs
93 | functorIdentity : forall a . (xs : List a) -> map Prelude.id xs = xs
94 | functorIdentity [] = Refl
95 | functorIdentity (x :: xs) = cong2 (::) Refl (functorIdentity xs)
99 | data All2 : (0 p : a -> b -> Type) -> List a -> List b -> Type where
101 | (::) : forall xs, ys . p x y -> All2 p xs ys -> All2 p (x :: xs) (y :: ys)
105 | length : All2 f xs ys -> Nat
107 | length (_ :: xs) = S (length xs)
111 | mapProperty : (forall x, y . f x y -> g x y) -> All2 f xs ys -> All2 g xs ys
112 | mapProperty f [] = []
113 | mapProperty f (x :: xs) = f x :: mapProperty f xs
118 | Applicative m => All2 f xs ys -> (forall x, y . f x y -> m (g x y)) -> m (All2 g xs ys)
119 | forProperty [] _ = pure []
120 | forProperty (z :: zs) f = [| f z :: forProperty zs f |]
126 | data Sorted : (a -> a -> Type) -> List a -> Type where
131 | SOne : Sorted f [x]
134 | SCons : (y : a) -> f y x -> Sorted f (x :: xs) -> Sorted f (y :: x :: xs)
138 | inBoundsCons : (xs : List a) -> InBounds k xs -> InBounds k (x :: xs)
139 | inBoundsCons _ InFirst = InFirst
140 | inBoundsCons (_ :: ys) (InLater prf) = InLater (inBoundsCons ys prf)