Asq
08/10/2021, 9:12 PM1: val aut = setOf(2, 3, 1, 4, 0)
2: print("$aut")
3: val aux2a: List<Int> = aut.dropWhile{ 2 < it }
4: a2.containsAll(aux2a) shouldBe true
5: (aux2a.size < a2.size) shouldBe true
fails (i.e. (aux2a.size < a2.size)
is false
) at line 5. the documentation for dropWhile
says :
Returns a list containing all elements except first elements that satisfy the given predicate.
I would have expected that at least item 3
(from line 1) xor item 4
would have been dropped. Perhaps both under certain circumstances (ordering is not a property of Set
). What is the expected behavior of dropWhile
for a Set?robstoll
08/10/2021, 9:14 PM2
does not meed your predicate (2 < 2
), so it stops dropping.Asq
08/10/2021, 9:16 PMSet
, dropWhile may drop none or any arbitrary number of items matching a predicate. Is that impression correct?Paul Griffith
08/10/2021, 9:19 PMPaul Griffith
08/10/2021, 9:19 PMAsq
08/10/2021, 9:20 PMdropWhile
on a Set
is a good operation to avoid, then.Paul Griffith
08/10/2021, 9:22 PMdropWhile
is an extension on Iterable, so that it works on Set is more of a consequence of type limitations than any deliberate decisions I'd sayAsq
08/10/2021, 9:23 PMephemient
08/10/2021, 9:47 PMephemient
08/10/2021, 9:48 PMephemient
08/10/2021, 9:49 PMSet
, but you may know it for particular instancesAsq
08/11/2021, 2:12 AM