https://kotlinlang.org logo
#atrium
Title
# atrium
i

Igor Akkerman

01/06/2020, 12:18 PM
One question regarding collections,: In my project, the lists are quite large, is there a way to specify (for in order comparisons) to only show the wrong values so that you don't have to search the front x's through the whole list?
r

robstoll

01/06/2020, 12:34 PM
Not yet out of the box but please open an issue for it, I'll provide a flag for this
i

Igor Akkerman

01/06/2020, 12:40 PM
Great, will do that, thank you!
👍 1
r

robstoll

01/06/2020, 1:03 PM
do you deal with `List`s?
i

Igor Akkerman

01/06/2020, 1:04 PM
Yes
r

robstoll

01/06/2020, 1:05 PM
and do you check against values or do you specify sub-assertions?
based on your last question I guess sub-assertions: You could use the following function in the meantime:
Copy code
fun <E, T : List<E>> Expect<T>.containsInOrderOnly(vararg assertionCreators: Expect<E>.() -> Unit): Expect<T> =
    and {
        assertionCreators.forEachIndexed { index, assertionCreator ->
            get(index, assertionCreator)
        }
    }
remove the
and
in case you want fail-fast behaviour
i

Igor Akkerman

01/06/2020, 1:14 PM
just values in that case
r

robstoll

01/06/2020, 1:14 PM
from another list?
i

Igor Akkerman

01/06/2020, 1:15 PM
the subject is a list, the arguments of
containsExactly
are varargs
r

robstoll

01/06/2020, 1:16 PM
assuming you are not dealing with nullable values
Copy code
fun <E: Any, T : List<E>> Expect<T>.containsInOrderOnly(vararg values: E): Expect<T> =
    and {
        values.forEachIndexed { index, value ->
            get(index).toBe(value)
        }
    }
i

Igor Akkerman

01/06/2020, 1:21 PM
Wow, excellent, thanks!
r

robstoll

01/06/2020, 1:22 PM
no worries, but please still create an issue, it makes more sense that this can be configured somehow instead of a separate function
otherwise you could still use:
Copy code
fun <E> Expect<Sequence<E>>.asList(): Expect<List<E>> = ExpectImpl.changeSubject(this).unreported { it.toList() }
and then the function above. But note that ExpectImpl is not stable yet and most likely changes
i

Igor Akkerman

01/06/2020, 1:29 PM
cool, thanks a lot
r

robstoll

01/06/2020, 1:31 PM
you're welcome
i

Igor Akkerman

01/06/2020, 8:38 PM
I created the issue on GitHub, as discussed: https://github.com/robstoll/atrium/issues/292
4 Views