final class FoldableOps[F[_], A] extends AnyVal
- Alphabetic
- By Inheritance
- FoldableOps
- AnyVal
- Any
- Hide All
- Show All
- Public
- All
Instance Constructors
- new FoldableOps(fa: F[A])
Value Members
-
final
def
!=(arg0: Any): Boolean
- Definition Classes
- Any
-
final
def
##(): Int
- Definition Classes
- Any
-
final
def
==(arg0: Any): Boolean
- Definition Classes
- Any
-
final
def
asInstanceOf[T0]: T0
- Definition Classes
- Any
-
def
collectFirstSomeM[G[_], B](f: (A) ⇒ G[Option[B]])(implicit F: Foldable[F], G: Monad[G]): G[Option[B]]
Monadic version of
collectFirstSome
.Monadic version of
collectFirstSome
.If there are no elements, the result is
None
.collectFirstSomeM
short-circuits, i.e. once a Some element is found, no further effects are produced.For example:
scala> import cats.implicits._ scala> def parseInt(s: String): Either[String, Int] = Either.catchOnly[NumberFormatException](s.toInt).leftMap(_.getMessage) scala> val keys1 = List("1", "2", "4", "5") scala> val map1 = Map(4 -> "Four", 5 -> "Five") scala> keys1.collectFirstSomeM(parseInt(_) map map1.get) res0: scala.util.Either[String,Option[String]] = Right(Some(Four)) scala> val map2 = Map(6 -> "Six", 7 -> "Seven") scala> keys1.collectFirstSomeM(parseInt(_) map map2.get) res1: scala.util.Either[String,Option[String]] = Right(None) scala> val keys2 = List("1", "x", "4", "5") scala> keys2.collectFirstSomeM(parseInt(_) map map1.get) res2: scala.util.Either[String,Option[String]] = Left(For input string: "x") scala> val keys3 = List("1", "2", "4", "x") scala> keys3.collectFirstSomeM(parseInt(_) map map1.get) res3: scala.util.Either[String,Option[String]] = Right(Some(Four))
-
def
collectFold[M](f: PartialFunction[A, M])(implicit F: Foldable[F], M: Monoid[M]): M
Tear down a subset of this structure using a
PartialFunction
.Tear down a subset of this structure using a
PartialFunction
.scala> import cats.implicits._ scala> val xs = List(1, 2, 3, 4) scala> xs.collectFold { case n if n % 2 == 0 => n } res0: Int = 6
-
def
contains_(v: A)(implicit ev: Eq[A], F: Foldable[F]): Boolean
test if
F[A]
contains anA
, named contains_ to avoid conflict with existing contains which uses universal equalitytest if
F[A]
contains anA
, named contains_ to avoid conflict with existing contains which uses universal equalityExample:
scala> import cats.implicits._ scala> val l: List[Int] = List(1, 2, 3, 4) scala> l.contains_(1) res0: Boolean = true scala> l.contains_(5) res1: Boolean = false
-
def
findM[G[_]](p: (A) ⇒ G[Boolean])(implicit F: Foldable[F], G: Monad[G]): G[Option[A]]
Find the first element matching the effectful predicate, if one exists.
Find the first element matching the effectful predicate, if one exists.
If there are no elements, the result is
None
.findM
short-circuits, i.e. once an element is found, no further effects are produced.For example:
scala> import cats.implicits._ scala> val list = List(1,2,3,4) scala> list.findM(n => (n >= 2).asRight[String]) res0: Either[String,Option[Int]] = Right(Some(2)) scala> list.findM(n => (n > 4).asRight[String]) res1: Either[String,Option[Int]] = Right(None) scala> list.findM(n => Either.cond(n < 3, n >= 2, "error")) res2: Either[String,Option[Int]] = Right(Some(2)) scala> list.findM(n => Either.cond(n < 3, false, "error")) res3: Either[String,Option[Int]] = Left(error)
- def foldA[G[_], B](implicit F: Foldable[F], ev: <:<[A, G[B]], G: Applicative[G], B: Monoid[B]): G[B]
-
def
foldSmash(prefix: A, delim: A, suffix: A)(implicit A: Monoid[A], F: Foldable[F]): A
Intercalate with a prefix and a suffix
Intercalate with a prefix and a suffix
Example:
scala> import cats.implicits._ scala> val l: List[String] = List("1", "2", "3") scala> l.foldSmash("List(", ",", ")") res0: String = List(1,2,3)
- def foldl[B](b: B)(f: (B, A) ⇒ B)(implicit F: Foldable[F]): B
- def foldr[B](b: Eval[B])(f: (A, Eval[B]) ⇒ Eval[B])(implicit F: Foldable[F]): Eval[B]
-
def
getClass(): Class[_ <: AnyVal]
- Definition Classes
- AnyVal → Any
-
final
def
isInstanceOf[T0]: Boolean
- Definition Classes
- Any
-
def
mkString_(prefix: String, delim: String, suffix: String)(implicit A: Show[A], F: Foldable[F]): String
Make a string using
Show
, prefix, delimiter, and suffix.Make a string using
Show
, prefix, delimiter, and suffix.Named as
mkString_
to avoid conflict.Example:
scala> import cats.implicits._ scala> val l: List[Int] = List(1, 2, 3) scala> l.mkString_("L[", ";", "]") res0: String = L[1;2;3] scala> val el: List[Int] = List() scala> el.mkString_("L[", ";", "]") res1: String = L[]
-
def
toString(): String
- Definition Classes
- Any
Deprecated Value Members
-
def
collectSomeFold[M](f: (A) ⇒ Option[M])(implicit F: Foldable[F], M: Monoid[M]): M
Tear down a subset of this structure using a
A => Option[M]
.Tear down a subset of this structure using a
A => Option[M]
.scala> import cats.implicits._ scala> val xs = List(1, 2, 3, 4) scala> def f(n: Int): Option[Int] = if (n % 2 == 0) Some(n) else None scala> xs.collectFoldSome(f) res0: Int = 6
- Annotations
- @deprecated
- Deprecated
(Since version 2.1.0-RC1) Use collectFoldSome