diff --git a/src/Data/Vec.hs b/src/Data/Vec.hs index 489c3c1..b4191e8 100644 --- a/src/Data/Vec.hs +++ b/src/Data/Vec.hs @@ -320,6 +320,28 @@ drop' SZ x = x drop' (SS n) (x :- xs) = drop' n xs +-- * Searching vectors +-- Searching by equality + +-- | Does the element occur in the structure? +elem ∷ Eq a ⇒ Vec a n → a → 𝔹 +elem Nil _ = F +elem (x :- xs) y = (x ≡ y) ∨ (elem xs y) + + +-- | 'notElem' is the negation of 'elem'. +notElem ∷ Eq a ⇒ Vec a n → a → 𝔹 +notElem xs = (¬) ∘ elem xs + + +-- | 'lookup' key assocs looks up a key in an association vector. +lookup ∷ Eq a ⇒ a → Vec (a, b) n → Maybe b +lookup t Nil = Nothing +lookup t ((k,v) :- x) = + if t ≡ k + then Just v + else lookup t x + -- * Zipping and unzipping vectors