We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 803107d commit 0ee49e6Copy full SHA for 0ee49e6
core/src/main/scala/cats/instances/map.scala
@@ -46,14 +46,9 @@ trait MapInstances extends cats.kernel.instances.MapInstances {
46
else
47
G match {
48
case x: StackSafeMonad[G] =>
49
- x.map(fa.foldLeft(G.pure(Map.newBuilder[K, B])) { case (accG, (k, a)) =>
50
- x.flatMap(accG) { acc =>
51
- G.map(f(a)) { a =>
52
- acc += k -> a
53
- acc
54
- }
55
56
- })(_.result())
+ fa.iterator.foldLeft(G.pure(Map.empty[K, B])) { case (accG, (k, a)) =>
+ x.map2(accG, f(a)) { case (acc, b) => acc + (k -> b) }
+ }
57
case _ =>
58
G.map(Chain.traverseViaChain(fa.toIndexedSeq) { case (k, a) =>
59
G.map(f(a))((k, _))
0 commit comments