any nicer way to write something like this? ```lis...
# kotest
h
any nicer way to write something like this?
Copy code
list.none { it is State.StateA } shouldBe true
Goal is, to check if the list does not contain an element which matches a given predicate
r
Hi @Henning B, that looks good to me but perhaps if you have a known value then you may alternatively use
!in
Copy code
val x: Boolean = listOf(1, 2, 3).none { it == 1 } //false
val y: Boolean = 1 !in listOf(1, 2, 3) //false
t
Maybe:
Copy code
list shouldNot singleElement { it is State.StateA }
You could also extract this into another function like
Copy code
infix fun <T> Collection<T>.shouldNotHaveSingleElement(t: T) = this shouldNot singleElement(t)
s
There is always .forNone too
h
Thanks!
I ended up with:
Copy code
states.forAll { state -> state.shouldNotBeTypeOf<State.StateA>() }
e
somewhat related, perhaps you have some opinions to add https://github.com/kotest/kotest/pull/2321 🙂