on master help sign in
Merge pull request #2163 from JakobBruenker/vecfin

changed Vect.findIndex to return Fins

commit217c6697a0b753f24007c079534fbd4942afa311 authorDavid Christiansen <david@davidchristiansen.dk> dateMon 20 Apr 2015, 18:39 (12 years ago) parente5c915d47ae3e8
2 files changed+9−10
CHANGELOG+2 libs/base/Data/VectType.idr+7−10
CHANGELOG+2
@@ -28,6 +28,8 @@ New in 0.9.18:
2828 choice, keeping the first success as Alternative does. The version that
2929 collects successes is now a named instance.
3030* :exec REPL command now takes an optional expression to compile and run/show
31+* The return types of `Vect.findIndex`, `Vect.elemIndex` and
32+ `Vect.elemIndexBy` were changed from `Maybe Nat` to `Maybe (Fin n)`
3133
3234New in 0.9.17:
3335--------------
libs/base/Data/VectType.idr+7−10
@@ -372,14 +372,11 @@ find p (x::xs) with (p x)
372372 | False = find p xs
373373
374374||| Find the index of the first element of the vector that satisfies some test
375−findIndex : (a -> Bool) -> Vect n a -> Maybe Nat
376−findIndex = findIndex' 0
377− where
378− findIndex' : Nat -> (a -> Bool) -> Vect n a -> Maybe Nat
379− findIndex' cnt p [] = Nothing
380− findIndex' cnt p (x::xs) with (p x)
381− | True = Just cnt
382− | False = findIndex' (S cnt) p xs
375+findIndex : (a -> Bool) -> Vect n a -> Maybe (Fin n)
376+findIndex p [] = Nothing
377+findIndex p (x :: xs) with (p x)
378+ | True = Just 0
379+ | False = map FS (findIndex p xs)
383380
384381||| Find the indices of all elements that satisfy some test
385382total findIndices : (a -> Bool) -> Vect m a -> (p ** Vect p Nat)
@@ -394,10 +391,10 @@ findIndices = findIndices' 0
394391 else
395392 (_ ** tail)
396393
397−elemIndexBy : (a -> a -> Bool) -> a -> Vect m a -> Maybe Nat
394+elemIndexBy : (a -> a -> Bool) -> a -> Vect m a -> Maybe (Fin m)
398395elemIndexBy p e = findIndex $ p e
399396
400−elemIndex : Eq a => a -> Vect m a -> Maybe Nat
397+elemIndex : Eq a => a -> Vect m a -> Maybe (Fin m)
401398elemIndex = elemIndexBy (==)
402399
403400total elemIndicesBy : (a -> a -> Bool) -> a -> Vect m a -> (p ** Vect p Nat)