Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

572
Views
What's the difference between sumOf() and sumBy() in Kotlin 1.4?

How is the new sumOf() function in Kotlin 1.4 different from sumBy() or sumByDouble() functions?

over 4 years ago · Hanz Gallego
2 answers
Answer question

0

As the Kotlin 1.4 changelog states:

... sumOf lets you handle sums of different types in the same way. it produces sums of the types Int, Long, Double, ... [depending on the return type of the given lambda].

over 4 years ago · Hanz Gallego Report

0

TLDR: there's no difference, and eventually sumBy/sumByDouble can be deprecated in favor of the single sumOf.

sumOf operation has overloads for different numeric types returned from the selector function. It's something that was impossible previously with the old type inference facility, so in order to handle different numeric types it was required to have functions with the different names: sumBy to sum ints, sumByDouble to sum doubles, etc.

When the new inference has finally arrived with the experimental support of overload resolution by selector lambda return type, we've decided not to overload the existing sumBy function, but to introduce a new operation sumOf. This way it has less chance of breaking something and is more consistent in naming with the new operations list.minOf/maxOf { selector }.

over 4 years ago · Hanz Gallego Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!