beginner

sum

sum adds up all the values of a selected numeric property and returns the total sum as a Long

sum over List

import arrow.aql.instances.list.select.*
import arrow.aql.instances.list.where.*
import arrow.aql.instances.list.sum.*
import arrow.aql.instances.listk.select.selectAll
import arrow.aql.instances.id.select.value

data class Student(val name: String, val age: Int)

val john = Student("John", 30)
val jane = Student("Jane", 32)
val jack = Student("Jack", 32)

fun main(args: Array<String>) {
//sampleStart
val result = 
  listOf(john, jane, jack).query {
    selectAll() where { age > 30 } sum { age.toLong() }
  }.value()
//sampleEnd
println(result)
}

intermediate

sum works with any data type that provides an instance of Foldable<F> where F is the higher kinded representation of the data type. For example ForOption when targeting the Option<A> data type or ForListK when targeting the List<A> data type

Learn more about the AQL combinators

Supported Data types

Module Data types
arrow.core Either, Option, Try
arrow.data ListK, NonEmptyList, SequenceK

advanced

Adapt AQL to your own custom data types