Field

sealed interface Field<ID : Any, out T>

A field is a map of messages where the key is the ID of a node and T the associated value.

Types

Link copied to clipboard
object Companion

Base operations on Fields.

Properties

Link copied to clipboard
abstract val localId: ID

The ID of the local node.

Link copied to clipboard
abstract val localValue: T

The value associated with the localId.

Link copied to clipboard
abstract val neighbors: Collection<ID>

Returns the IDs of all neighbors in this field.

Link copied to clipboard

Returns the number of neighbors of the field.

Functions

Link copied to clipboard
open fun <B, R> alignedMap(other: Field<ID, B>, transform: (T, B) -> R): Field<ID, R>

Combines this field with another (aligned) one.

Link copied to clipboard
inline fun <ID : Any, T> Field<ID, T>.all(crossinline predicate: (T) -> Boolean): Boolean

Check if all the elements in the field satisfy the predicate, ignoring the local value.

fun <ID : Any> Field<ID, Boolean>.all(base: Boolean, predicate: (Boolean) -> Boolean = { it }): Boolean

Check if all the Boolean elements in the field are true by default. If predicate is defined, it is applied to the elements. The base value is used as a first element to start the fold operation at which the predicate is applied.

Link copied to clipboard
inline fun <ID : Any, T> Field<ID, T>.allWithSelf(crossinline predicate: (T) -> Boolean): Boolean

Check if all the elements in the field satisfy the predicate, including the local value.

Link copied to clipboard
inline fun <ID : Any, T> Field<ID, T>.any(crossinline predicate: (T) -> Boolean): Boolean

Check if any of the elements in the field satisfy the predicate, ignoring the local value.

fun <ID : Any> Field<ID, Boolean>.any(base: Boolean, predicate: (Boolean) -> Boolean = { it }): Boolean

Check if any of the Boolean elements in the field are true by default. If predicate is defined, it is applied to the elements. The base value is used as a first element to start the fold operation at which the predicate is applied.

Link copied to clipboard
inline fun <ID : Any, T> Field<ID, T>.anyWithSelf(crossinline predicate: (T) -> Boolean): Boolean

Check if any of the elements in the field satisfy the predicate, including the local value.

Link copied to clipboard
abstract fun asSequence(): Sequence<Pair<ID, T>>

Transform the field into a map.

Link copied to clipboard
inline fun <ID : Any, T> Field<ID, T>.count(crossinline predicate: (T) -> Boolean = { true }): Int

Count the number of elements in the field that satisfy the predicate, ignoring the local value.

Link copied to clipboard
inline fun <ID : Any, T> Field<ID, T>.countWithSelf(crossinline predicate: (T) -> Boolean = { true }): Int

Count the number of elements in the field that satisfy the predicate, including the local value.

Link copied to clipboard
abstract fun excludeSelf(): Map<ID, T>

Returns a Map with the neighboring values of this field (namely, all values but self).

Link copied to clipboard
fun <ID : Any, T, R> Field<ID, T>.fold(initial: R, transform: (R, T) -> R): R

Folds the elements of a field starting with an initial through a transform function. The local value is not considered, unless explicitly passed as initial.

Link copied to clipboard
abstract operator fun get(id: ID): T

Get the value associated with the id. Raise an error if the id is not present in the field.

Link copied to clipboard
fun <ID : Any, T> Field<ID, T>.hood(default: T, transform: (T, T) -> T): T

Reduce the elements of the field using the transform function. The local value is not considered, unless explicitly passed as default.

Link copied to clipboard
open fun <B> map(transform: (T) -> B): Field<ID, B>

Map the field using the transform function.

Link copied to clipboard
open fun <B> mapToConstantField(singleton: B): Field<ID, B>

Map the field resulting in a new one where the value for the local and the neighbors is singleton.

Link copied to clipboard
abstract fun <B> mapWithId(transform: (ID, T) -> B): Field<ID, B>

Map the field using the transform function.

Link copied to clipboard
fun <ID : Any, T : Comparable<T>> Field<ID, T>.max(base: T): T

Get the maximum value of a field, excluding the local value, starting from base. To consider the local value, explicitly provide it as base.

Link copied to clipboard
inline fun <ID : Any, T, R : Comparable<R>> Field<ID, T>.maxBy(base: T, crossinline selector: (T) -> R): T

Returns the element yielding the largest value of the given selector. In case multiple elements are maximal, there is no guarantee which one will be returned.

Link copied to clipboard
fun <ID : Any, T> Field<ID, T>.maxWith(base: T, comparator: Comparator<T>): T

Returns the element yielding the largest value of the given comparator. In case multiple elements are maximal, there is no guarantee which one will be returned.

Link copied to clipboard
fun <ID : Any, T : Comparable<T>> Field<ID, T>.maxWithSelf(): T

Get the maximum value of a field, including the local value.

Link copied to clipboard
fun <ID : Any, T : Comparable<T>> Field<ID, T>.min(base: T): T

Get the minimum value of a field, excluding the local value, starting from base. To consider the local value, explicitly provide it as base.

Link copied to clipboard
inline fun <ID : Any, T, R : Comparable<R>> Field<ID, T>.minBy(base: T, crossinline selector: (T) -> R): T

Returns the element yielding the smallest value of the given selector. In case multiple elements are minimal, there is no guarantee which one will be returned.

Link copied to clipboard
fun <ID : Any, T> Field<ID, T>.minWith(base: T, comparator: Comparator<T>): T

Returns the element yielding the smallest value of the given comparator. In case multiple elements are minimal, there is no guarantee which one will be returned.

Link copied to clipboard
fun <ID : Any, T : Comparable<T>> Field<ID, T>.minWithSelf(): T

Get the minimum value of a field, including the local value.

Link copied to clipboard
inline fun <ID : Any, T> Field<ID, T>.none(crossinline predicate: (T) -> Boolean): Boolean

Check if none of the elements in the field satisfy the predicate, ignoring the local value.

fun <ID : Any> Field<ID, Boolean>.none(base: Boolean, predicate: (Boolean) -> Boolean = { it }): Boolean

Check if none of the Boolean elements in the field are true by default. If predicate is defined, it is applied to the elements. The base value is used as a first element to start the fold operation at which the predicate is applied.

Link copied to clipboard
inline fun <ID : Any, T> Field<ID, T>.noneWithSelf(crossinline predicate: (T) -> Boolean): Boolean

Check if none of the elements in the field satisfy the predicate, including the local value.

Link copied to clipboard
abstract fun toMap(): Map<ID, T>

Converts the Field into a Map. This method is meant to bridge the aggregate APIs with the Kotlin collections framework. The resulting map will contain the local value.