Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

565
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda