where

where allows filtering data from any given data source providing a predicate function of the shape (A) -> Boolean. Whenever true is returned from an expression affecting one of the items in the data source the item is collected and included in the selection.

where over List

import arrow.aql.extensions.list.select.*
import arrow.aql.extensions.list.where.*
import arrow.aql.extensions.listk.select.select

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: List<String> =
  listOf(john, jane, jack).query {
    select { name } where { age > 20 }
  }.value()
//sampleEnd
println(result)
}

where works with any data type that provides an instance of FunctorFilter<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 ListK, Option, SequenceK

Adapt AQL to your own custom data types

Do you like Arrow?

Arrow Org
<