@@ -578,42 +578,58 @@ trait Foldable[F[_]] extends UnorderedFoldable[F] with FoldableNFunctions[F] { s
578
578
* scala> import cats.syntax.all._
579
579
* scala> def parseInt(s: String): Option[Int] = Either.catchOnly[NumberFormatException](s.toInt).toOption
580
580
* scala> val F = Foldable[List]
581
- * scala> F.traverse_ (List("333", "444"))(parseInt)
581
+ * scala> F.traverseVoid (List("333", "444"))(parseInt)
582
582
* res0: Option[Unit] = Some(())
583
- * scala> F.traverse_ (List("333", "zzz"))(parseInt)
583
+ * scala> F.traverseVoid (List("333", "zzz"))(parseInt)
584
584
* res1: Option[Unit] = None
585
585
* }}}
586
586
*
587
587
* This method is primarily useful when `G[_]` represents an action
588
588
* or effect, and the specific `A` aspect of `G[A]` is not otherwise
589
589
* needed.
590
590
*/
591
- def traverse_ [G [_], A , B ](fa : F [A ])(f : A => G [B ])(implicit G : Applicative [G ]): G [Unit ] =
591
+ def traverseVoid [G [_], A , B ](fa : F [A ])(f : A => G [B ])(implicit G : Applicative [G ]): G [Unit ] =
592
592
foldRight(fa, Always (G .unit)) { (a, acc) =>
593
593
G .map2Eval(f(a), acc) { (_, _) =>
594
594
()
595
595
}
596
596
}.value
597
597
598
+ /**
599
+ * Alias for `traverseVoid`.
600
+ *
601
+ * @deprecated this method should be considered as deprecated and replaced by `traverseVoid`.
602
+ */
603
+ def traverse_ [G [_], A , B ](fa : F [A ])(f : A => G [B ])(implicit G : Applicative [G ]): G [Unit ] =
604
+ traverseVoid(fa)(f)
605
+
598
606
/**
599
607
* Sequence `F[G[A]]` using `Applicative[G]`.
600
608
*
601
- * This is similar to `traverse_ ` except it operates on `F[G[A]]`
609
+ * This is similar to `traverseVoid ` except it operates on `F[G[A]]`
602
610
* values, so no additional functions are needed.
603
611
*
604
612
* For example:
605
613
*
606
614
* {{{
607
615
* scala> import cats.syntax.all._
608
616
* scala> val F = Foldable[List]
609
- * scala> F.sequence_ (List(Option(1), Option(2), Option(3)))
617
+ * scala> F.sequenceVoid (List(Option(1), Option(2), Option(3)))
610
618
* res0: Option[Unit] = Some(())
611
- * scala> F.sequence_ (List(Option(1), None, Option(3)))
619
+ * scala> F.sequenceVoid (List(Option(1), None, Option(3)))
612
620
* res1: Option[Unit] = None
613
621
* }}}
614
622
*/
623
+ def sequenceVoid [G [_]: Applicative , A ](fga : F [G [A ]]): G [Unit ] =
624
+ traverseVoid(fga)(identity)
625
+
626
+ /**
627
+ * Alias for `sequenceVoid`.
628
+ *
629
+ * @deprecated this method should be considered as deprecated and replaced by `sequenceVoid`.
630
+ */
615
631
def sequence_ [G [_]: Applicative , A ](fga : F [G [A ]]): G [Unit ] =
616
- traverse_ (fga)(identity )
632
+ sequenceVoid (fga)
617
633
618
634
/**
619
635
* Fold implemented using the given `MonoidK[G]` instance.
@@ -1053,10 +1069,17 @@ object Foldable {
1053
1069
typeClassInstance.foldMapM[G , A , B ](self)(f)(G , B )
1054
1070
def foldMapA [G [_], B ](f : A => G [B ])(implicit G : Applicative [G ], B : Monoid [B ]): G [B ] =
1055
1071
typeClassInstance.foldMapA[G , A , B ](self)(f)(G , B )
1072
+ def traverseVoid [G [_], B ](f : A => G [B ])(implicit G : Applicative [G ]): G [Unit ] =
1073
+ typeClassInstance.traverseVoid[G , A , B ](self)(f)(G )
1056
1074
def traverse_ [G [_], B ](f : A => G [B ])(implicit G : Applicative [G ]): G [Unit ] =
1057
- typeClassInstance.traverse_[G , A , B ](self)(f)(G )
1075
+ traverseVoid[G , B ](f)
1076
+ // TODO: looks like these two methods below duplicate the same named methods from `NestedFoldableOps`.
1077
+ // Moreover, the other two methods take precedence, thereby these two are not in use whatsoever.
1078
+ // Perhaps it makes sense to deprecate one pair of them either here or there.
1079
+ def sequenceVoid [G [_], B ](implicit ev$1 : A <:< G [B ], ev$2 : Applicative [G ]): G [Unit ] =
1080
+ typeClassInstance.sequenceVoid[G , B ](self.asInstanceOf [F [G [B ]]])
1058
1081
def sequence_ [G [_], B ](implicit ev$1 : A <:< G [B ], ev$2 : Applicative [G ]): G [Unit ] =
1059
- typeClassInstance.sequence_ [G , B ](self. asInstanceOf [ F [ G [ B ]]])
1082
+ sequenceVoid [G , B ]
1060
1083
def foldK [G [_], B ](implicit ev$1 : A <:< G [B ], G : MonoidK [G ]): G [B ] =
1061
1084
typeClassInstance.foldK[G , B ](self.asInstanceOf [F [G [B ]]])(G )
1062
1085
def find (f : A => Boolean ): Option [A ] = typeClassInstance.find[A ](self)(f)
0 commit comments