dave08
10/23/2017, 8:24 PMvoddan
10/23/2017, 8:27 PMvoddan
10/23/2017, 8:30 PMdave08
10/23/2017, 8:30 PMvoddan
10/23/2017, 8:33 PMdave08
10/23/2017, 8:36 PMvoddan
10/23/2017, 8:38 PMbuildSequence
is kinda a side use of Coroutines, but it is nice to have, especially since K is trying to compete withy Pythondave08
10/23/2017, 8:42 PMdave08
10/23/2017, 8:44 PMgroostav
10/24/2017, 5:46 PMgenerateSequence
will often require a when
statement where buildSequence
doesn't. I've used this for test-data where I want lazy creation of elements (IE, I cant simply enumerate them eagerly), consider:
val resources = buildSequence {
yield(makeExpensiveResourceOne())
yield(makeExpensiveResourceTwo())
}
with generate sequence
//no good, its eager
val resources = listOf(makeResourceOne(), makeResourceTwo()).toSeq()
val resources = (1 .. 2).toSeq().map {
when(it) {
1 -> makeExpensiveResourceOne()
2 -> makeExpensiveResourceTwo()
}
}
dave08
10/24/2017, 5:55 PMval resources = listOf(::makeExpensiveResourceOne,::makeExpensiveResourceTwo).toSeq().map { it() }
groostav
10/24/2017, 10:26 PMgroostav
10/24/2017, 10:26 PMgroostav
10/24/2017, 10:27 PMgroostav
10/24/2017, 10:29 PMasync void doAnimation(){
characterModel.displayedFrame = hitFrame[0]
characterModel.location -= 5
nextFrame() //suspending function
characterModel.displaedFrame = hitFrame[1]
characterModel.location -= 2
nextFrame()
}
dave08
10/25/2017, 2:22 AMbuildSequence
is better than regular Kotlin sequence generators, like with yield on conditions and yieldall that can produce many next values in one shot that can be iterated through one by one.
Whereas regular sequences can generate only the next value from an isolated computation or as an accumulation of a previous result apon iterating through each value
So for concurrency there are no advantages over sequences, but there are more options on how to actually generate them.