adam-mcneilly
12/05/2017, 3:48 AMlist.map { it * 2 }
and list.asSequence().map { it * 2 }.toList()
? Also accepting links to posts/youtube videos that explain it if it's a rabbit hole.stkent
12/05/2017, 4:02 AM/**
* Classes that inherit from this interface can be represented as a sequence of elements that can
* be iterated over.
* @param T the type of element being iterated over. The iterator is covariant on its element type.
*/
public interface Iterable<out T> {
/**
* Returns an iterator over the elements of this object.
*/
public operator fun iterator(): Iterator<T>
}
vs
public interface Sequence<out T> {
/**
* Returns an [Iterator] that returns the values from the sequence.
*
* Throws an exception if the sequence is constrained to be iterated once and `iterator` is invoked the second time.
*/
public operator fun iterator(): Iterator<T>
}
stkent
12/05/2017, 4:02 AMgjesse
12/05/2017, 4:03 AMadam-mcneilly
12/05/2017, 4:06 AMedwardwongtl
12/05/2017, 4:12 AMgjesse
12/05/2017, 4:20 AMkotlin
fun main(args: Array<String>) {
(0 .. 20).map {
println(it)
it
}.filter {
it % 2 == 0
}.first()
(0 .. 20)
.asSequence()
.map {
println(it)
it
}.filter {
it % 2 == 0
}.first()
}
gjesse
12/05/2017, 4:21 AMgjesse
12/05/2017, 4:21 AMgjesse
12/05/2017, 4:22 AMadam-mcneilly
12/05/2017, 4:23 AMandyb
12/05/2017, 8:10 AMAndreas Sinz
12/05/2017, 8:43 AMAndreas Sinz
12/05/2017, 8:49 AMadam-mcneilly
12/05/2017, 2:55 PM