beginner

orderBy

orderBy and orderMap allows ordering selected data based on the actual data type Order<A> implementation. Data may be requested to be ordered ascending or descending. Ordering should be explicitly set as Ord.Asc for ascending order or Ord.Desc for descending order.

orderBy over List

import arrow.aql.instances.list.select.*
import arrow.aql.instances.list.orderBy.*
import arrow.aql.instances.listk.select.select
import arrow.instances.order
import arrow.aql.Ord

fun main(args: Array<String>) {
//sampleStart
val result = 
  listOf(1, 2, 3).query {
    select { this * 10 } orderBy Ord.Asc(Int.order())
  }
//sampleEnd
println(result)
}

orderMap over List

import arrow.aql.instances.list.select.*
import arrow.aql.instances.list.where.*
import arrow.aql.instances.list.groupBy.*
import arrow.aql.instances.list.orderBy.*
import arrow.aql.instances.listk.select.selectAll
import arrow.aql.instances.id.select.value
import arrow.instances.order
import arrow.aql.Ord

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() groupBy { age } orderMap Ord.Desc(Int.order())
  }
//sampleEnd
println(result)
}

intermediate

orderBy 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. The contained data inside the data type should also provide an instance for Order as in the examples above Int.order() : Order<Int>

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