We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 8bc7cab commit 11c0295Copy full SHA for 11c0295
src/Libraries/Base1/List.bs
@@ -119,6 +119,19 @@ lookup k xs = case (find (\x -> x.fst == k) xs) of
119
Nothing -> Nothing
120
Just (_,v) -> Just v
121
122
+--@ Lookup all values for a key in an association list.
123
+--@ \index{lookup@\te{lookup} (\te{List} function)}
124
+--@ \begin{libverbatim}
125
+--@ function List#(b) lookup (a k, List#(Tuple2#(a,b)) xs)
126
+--@ provisos(Eq#(a));
127
+--@ \end{libverbatim}
128
+lookupAll :: (Eq a) => a -> List (a, b) -> List b
129
+lookupAll k (Cons x xs) =
130
+ if x.fst == k
131
+ then x.snd :> lookupAll k xs
132
+ else lookupAll k xs
133
+lookupAll _ Nil = Nil
134
+
135
--@ Append two lists, return appended list.
136
--@ \index{append@\te{append} (\te{List} function)}
137
--@ \begin{libverbatim}
0 commit comments