igor.wojda
10/31/2018, 11:09 AMlist
contains items with the same value (we don’t know what value it may be). Is there any operator or combination fo operators to achieve this ?
eg `
listOf("A", "A", "A") //true
listOf("A", "A", "B") //false
`
edwardwongtl
10/31/2018, 11:10 AM.all {}
arekolek
10/31/2018, 11:11 AM.toSet().size == 1
igor.wojda
10/31/2018, 11:12 AMribesg
10/31/2018, 11:16 AMarekolek
10/31/2018, 11:16 AM.asSequence().zipWithNext().all { (a, b) -> a == b }
ribesg
10/31/2018, 11:16 AMarekolek
10/31/2018, 11:18 AMSequence
object that uses the iteratorribesg
10/31/2018, 11:18 AM.all
does stuff tooarekolek
10/31/2018, 11:20 AMSequence
, doesn’t create any objectsribesg
10/31/2018, 11:20 AMarekolek
10/31/2018, 11:20 AMribesg
10/31/2018, 11:22 AMEgor Trutenko
10/31/2018, 11:25 AMall
already does all the work 🤔arekolek
10/31/2018, 11:28 AMall
like this all { first() == it }
, is that what you mean?igor.wojda
10/31/2018, 11:32 AMdistinct
may be also an option
listOf(1, 1, 1).distinct().size == 1 //true
Egor Trutenko
10/31/2018, 11:32 AMall
doesn't helparekolek
10/31/2018, 11:33 AM.run { all { first() == it } }
makes more sense to me than the set or sequence onesEgor Trutenko
10/31/2018, 11:39 AMdsavvinov
10/31/2018, 12:02 PMall
over an empty collection is always true
, no matter what the passed predicate is (i.e. behaviour is different from the `toSet`/`distinct` approach)
See this demo: https://pl.kotl.in/r12sFGv2Xigor.wojda
10/31/2018, 1:07 PM