Skip to content

Commit 20b2649

Browse files
Avoid redundantantly touching graph nodes more than once
1 parent e6ac902 commit 20b2649

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/Data/Graph.purs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ instance functorGraph :: Functor (Graph k) where
3333
map f (Graph m) = Graph (map (lmap f) m)
3434

3535
instance foldableGraph :: Foldable (Graph k) where
36-
foldl f z (Graph m) = foldl f z $ fst <$> M.values m
37-
foldr f z (Graph m) = foldr f z $ fst <$> M.values m
38-
foldMap f (Graph m) = foldMap f $ fst <$> M.values m
36+
foldl f z (Graph m) = foldl (\acc (Tuple k _) -> f acc k) z $ M.values m
37+
foldr f z (Graph m) = foldr (\(Tuple k _) acc -> f k acc) z $ M.values m
38+
foldMap f (Graph m) = foldMap (f <<< fst) $ M.values m
3939

4040
instance traversableGraph :: Traversable (Graph k) where
4141
traverse f (Graph m) = Graph <$> (traverse (\(v /\ ks) -> (_ /\ ks) <$> (f v)) m)

0 commit comments

Comments
 (0)