dhinojosa,
@dhinojosa@mastodon.social avatar

complaint List.empty[Int].sum should return None, not 0.

ross,
@ross@rossabaker.com avatar

@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,
@dhinojosa@mastodon.social avatar

@ross Tears of joy. Thank you

ross,
@ross@rossabaker.com avatar

@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,
@dhinojosa@mastodon.social avatar

@ross But the imports should just be the standard:

import cats.*
import cats.implicits.*

if I am not mistaken and ready to roll!

  • All
  • Subscribed
  • Moderated
  • Favorites
  • programming
  • kavyap
  • InstantRegret
  • ethstaker
  • DreamBathrooms
  • mdbf
  • magazineikmin
  • thenastyranch
  • Youngstown
  • everett
  • slotface
  • osvaldo12
  • khanakhh
  • rosin
  • Durango
  • megavids
  • vwfavf
  • GTA5RPClips
  • cubers
  • tacticalgear
  • tester
  • cisconetworking
  • ngwrru68w68
  • Leos
  • normalnudes
  • provamag3
  • modclub
  • anitta
  • JUstTest
  • All magazines