File tree Expand file tree Collapse file tree 2 files changed +6
-0
lines changed
Expand file tree Collapse file tree 2 files changed +6
-0
lines changed Original file line number Diff line number Diff line change 4343
4444 for_ :: forall a b f m. (Functor m, Applicative m, Foldable f) => f a -> (a -> m b) -> m { }
4545
46+ lookup :: forall a b f. (Eq a, Foldable f) => a -> f (Tuple a b) -> Maybe b
47+
4648 mconcat :: forall f m. (Foldable f, Monoid m) => f m -> m
4749
4850 notElem :: forall a f. (Eq a, Foldable f) => a -> f a -> Prim.Boolean
Original file line number Diff line number Diff line change @@ -6,6 +6,7 @@ import Data.Either
66import Data.Eq
77import Data.Maybe
88import Data.Monoid
9+ import Data.Monoid.First
910import Data.Tuple
1011
1112class Foldable f where
@@ -97,6 +98,9 @@ find :: forall a f. (Foldable f) => (a -> Boolean) -> f a -> Maybe a
9798find p f = case foldMap (\x -> if p x then [x] else [] ) f of
9899 (x:_) -> Just x
99100 [] -> Nothing
101+
102+ lookup :: forall a b f . (Eq a , Foldable f ) => a -> f (Tuple a b ) -> Maybe b
103+ lookup a f = runFirst $ foldMap (\(Tuple a' b) -> First (if a == a' then Just b else Nothing )) f
100104
101105foreign import foldrArray
102106 " function foldrArray(f) {\
You can’t perform that action at this time.
0 commit comments