dhinojosa, 1 month ago #Scala complaint List.empty[Int].sum should return None, not 0.
#Scala complaint List.empty[Int].sum should return None, not 0.
List.empty[Int].sum
None
0
ross, 1 month ago @dhinojosa cats.Foldable is here to give everyone what they want: scala> import cats.syntax.all._ scala> List.empty[Int].combineAll val res1: Int = 0 scala> List.empty[Int].combineAllOption val res2: Option[Int] = None
@dhinojosa cats.Foldable is here to give everyone what they want:
cats.Foldable
scala> import cats.syntax.all._ scala> List.empty[Int].combineAll val res1: Int = 0 scala> List.empty[Int].combineAllOption val res2: Option[Int] = None
dhinojosa, 1 month ago @ross Tears of joy. Thank you
@ross Tears of joy. Thank you
ross, 1 month ago @dhinojosa The bad news is you need that import. The good news is it works on more containers than lists[1], and more elements than ints[2]! [1] - anything Foldable [2] - any Semigroup (for Option results) or Monoid (for non-Option results)
@dhinojosa The bad news is you need that import. The good news is it works on more containers than lists[1], and more elements than ints[2]!
[1] - anything Foldable [2] - any Semigroup (for Option results) or Monoid (for non-Option results)
dhinojosa, 1 month ago @ross But the imports should just be the standard: import cats.* import cats.implicits.* if I am not mistaken and ready to roll!
@ross But the imports should just be the standard:
import cats.* import cats.implicits.*
if I am not mistaken and ready to roll!
Add comment