Natalia Peterwas
05/17/2023, 7:26 AMs1
, s2
sequences? I would expect it to be the same as in lists.
// 1
val s1 = sequenceOf(1, 2, 3)
val s2 = sequenceOf(1, 2, 3)
s1.hashCode() == s2.hashCode() // false - why?
// 2
val l1 = sequenceOf(1, 2, 3).toList()
val l2 = sequenceOf(1, 2, 3).toList()
l1.hashCode() == l2.hashCode() // true - fine as lists contain the same items
ephemient
05/17/2023, 7:28 AMCLOVIS
05/17/2023, 7:29 AMephemient
05/17/2023, 7:30 AMNatalia Peterwas
05/17/2023, 7:32 AMNatalia Peterwas
05/17/2023, 7:35 AMval s1 = sequenceOf(1, 2, 3)
s1.forEach { println(it) }
s1.forEach { println(it) }
ephemient
05/17/2023, 7:39 AMephemient
05/17/2023, 7:43 AMvar i = 0
val s = generateSequence { ++i }.take(3)
s.forEach {}
s.forEach {}
throwsephemient
05/17/2023, 8:00 AMlistOf(1, 2, 3).iterator().asSequence()
that's basically the difference between Iterable and Sequence. the interface is similar but the expectations are different