Hullaballoonatic
07/19/2019, 6:32 PMoperator fun <T> Pair<T, T>.iterator() = object : Iterator<T> {
var i = 0
override fun hasNext() = i < 2
override fun next() = when (i++) {
0 -> first
1 -> second
else -> throw NoSuchElementException()
}
}
PHondogo
07/19/2019, 6:39 PMDominaezzz
07/19/2019, 6:40 PMoperator fun <T> Pair<T, T>.iterator() = sequence {
yield(first)
yield(second)
}.toIterator()
Hullaballoonatic
07/19/2019, 6:40 PMHullaballoonatic
07/19/2019, 6:40 PMHullaballoonatic
07/19/2019, 6:41 PMDominaezzz
07/19/2019, 6:41 PMDominaezzz
07/19/2019, 6:42 PMHullaballoonatic
07/19/2019, 6:43 PMDominaezzz
07/19/2019, 6:43 PMDominaezzz
07/19/2019, 6:44 PMHullaballoonatic
07/19/2019, 6:46 PMPHondogo
07/19/2019, 6:46 PMcbruegg
07/19/2019, 7:04 PMDominaezzz
07/19/2019, 7:06 PMHullaballoonatic
07/19/2019, 7:07 PMPair
to implement Iterable
to make generics easier. I admit that now I'm thinking it's more of a "why not?", and because Iterable
methods are nice. Treating a pair as an iterable is very intuitive, I think, though I think it is wonky that the iterator methods would return List
and Iterator
instead of Pair
Hullaballoonatic
07/19/2019, 7:08 PMDico
07/19/2019, 7:11 PMiterator {}
Dominaezzz
07/19/2019, 7:12 PM