From a1c9ff5d02f744cc6789627877c98059e6b4b3a5 Mon Sep 17 00:00:00 2001 From: Tim Spence Date: Fri, 25 Aug 2023 16:12:30 +0100 Subject: [PATCH] Use .void over .map(_ => ()) to give instances chance to optimize --- core/src/main/scala/cats/Traverse.scala | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/src/main/scala/cats/Traverse.scala b/core/src/main/scala/cats/Traverse.scala index 9109a860e1..fe1e62683f 100644 --- a/core/src/main/scala/cats/Traverse.scala +++ b/core/src/main/scala/cats/Traverse.scala @@ -310,11 +310,11 @@ object Traverse { val iter = fa.iterator if (iter.hasNext) { val first = iter.next() - G.map(iter.foldLeft(f(first)) { case (g, a) => + G.void(iter.foldLeft(f(first)) { case (g, a) => G.flatMap(g) { _ => f(a) } - })(_ => ()) + }) } else G.unit }