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
open fun <B, R> alignedMapWithId(other: Field<ID, B>, transform: (ID, T, B) -> R): Field<ID, R>

Combines this field with another (aligned) one considering the ID when combining the values.

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 sequence of pairs containing the ID and the associated value.

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
inline fun <ID : Any, T, R> Field<ID, T>.fold(initial: R, crossinline transform: (R, T) -> R): R

Accumulates the elements of a field starting from an initial through a transform function. The local value of the field is not considered.

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

Accumulates the elements of a field starting from an initial through a transform function that includes the ID of the element. The local value of the field is not considered.

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
inline fun <ID : Any, T> Field<ID, T>.hood(default: T, crossinline transform: (T, T) -> T): T

Reduce the elements of the field using the transform function, returning the default value if the field to transform is empty. The local value is not considered.

Link copied to clipboard
inline fun <ID : Any, T> Field<ID, T>.hoodWithId(default: T, crossinline transform: (Pair<ID, T>, Pair<ID, T>) -> Pair<ID, T>): T

Reduce the elements of the field using the transform function, returning the default value if the field to transform is empty. The local value is not considered.

inline fun <ID : Any, T> Field<ID, T>.hoodWithId(default: T, crossinline transform: (T, ID, T) -> T): T

Reduce the elements of the field using the transform function, it includes the ID of the element whenever it should be considered in the transform function, but the ID is not returned. The local value of the field is not considered. Returns the default if the field to transform is empty.

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
inline fun <ID : Any, T> Field<ID, T>.replaceMatching(replaceWith: T, crossinline predicate: (T) -> Boolean): Field<ID, T>

Returns a new field containing replaceWith for each element that satisfies the predicate.

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

Returns a new field containing replaceWith for each element that satisfies the predicate.

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.