diff --git a/dsl/src/commonMain/kotlin/it/unibo/collektive/field/operations/Fields.kt b/dsl/src/commonMain/kotlin/it/unibo/collektive/field/operations/Fields.kt index 5b4c75909..4ff6c1caa 100644 --- a/dsl/src/commonMain/kotlin/it/unibo/collektive/field/operations/Fields.kt +++ b/dsl/src/commonMain/kotlin/it/unibo/collektive/field/operations/Fields.kt @@ -4,8 +4,32 @@ package it.unibo.collektive.field.operations import it.unibo.collektive.field.Field import it.unibo.collektive.field.Field.Companion.fold +import it.unibo.collektive.field.Field.Companion.foldWithId +import kotlin.jvm.JvmName import kotlin.jvm.JvmOverloads +/** + * Check if the field contains the [value], **including the local value**. + * If you need to exclude the local value, use instead: + * + * ```kotlin + * value in field.withoutSelf().values + * ``` + */ +operator fun Field.contains(value: T): Boolean = anyWithSelf { it == value } + +/** + * Check if the field contains the [id], **including the local id**. + * If you need to exclude the local value, use instead: + * + * ```kotlin + * id in field.withoutSelf().keys + * ``` + */ +@JvmName("containsId") +operator fun Field.contains(id: ID): Boolean = + foldWithId(localValue == id) { current, id, _ -> current || id == id } + /** * Count the number of elements in the field that satisfy the [predicate], * ignoring the local value.