groupBy allows grouping data from a data source into different keys resulting in a map of keys and values.

groupBy over List

import arrow.aql.extensions.list.where.*
import arrow.aql.extensions.list.groupBy.*

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>) {
val result =
  listOf(john, jane, jack).query {
    selectAll() where { age > 30 } groupBy { age }

groupBy 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, ListK, NonEmptyList, Option, SequenceK, Try

Adapt AQL to your own custom data types

Do you like Arrow?

Arrow Org