Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(dsl): add Field.contains to enable the in operator #746

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe a test for these utilities, as suggested by codecov, would be useful

Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,32 @@

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 <ID : Any, T> Field<ID, T>.contains(value: T): Boolean = anyWithSelf { it == value }

Check warning on line 19 in dsl/src/commonMain/kotlin/it/unibo/collektive/field/operations/Fields.kt

View check run for this annotation

Codecov / codecov/patch

dsl/src/commonMain/kotlin/it/unibo/collektive/field/operations/Fields.kt#L19

Added line #L19 was not covered by tests

/**
* 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 <ID : Any, T> Field<ID, T>.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.
Expand Down
Loading