Daniele B
10/16/2020, 1:06 AMmylist.zip(mylist.drop(1)) { a, b -> myfunction(a,b) }
is there a way to zip 3 lists instead of 2?
something equivalent to this?
zip(mylist, mylist.drop(1), mylist.drop(2)) { a, b, c -> myfunction(a,b,c) }
I would like to create a new list of values, which are calculated based on the latest 3 valuesRuckus
10/16/2020, 1:49 AMwindowed functionDaniele B
10/16/2020, 1:57 AMmylist.windowed(2).map {
myfunction(it.get(0),it.get(1),it.get(2))
}
correct?ephemient
10/16/2020, 2:04 AMmylist.windowed(2).map {
myFunction(it[0], it[1], it[2])
}Ruckus
10/16/2020, 2:06 AMmylist.windowed(2).map { (a, b, c) ->
myFunction(a, b, c)
}Daniele B
10/16/2020, 2:08 AMmylist.windowed(8).map {
myFunction(it[0], it[1], it[7])
}
because I need to calculate differences by the day and by the week, so I need to take the value 1 index later and 7 indexes laterDaniele B
10/16/2020, 2:14 AMwindowed() is returning a list for each window:
https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/windowed.html
I wonder if that ends up being too expensive, and whether it’s more efficient to just use an imperative loopRuckus
10/16/2020, 2:18 AMephemient
10/16/2020, 2:20 AMmylist has random access then
List(mylist.size - 8) { myFunction(mylist[it], mylist[it + 1], mylist[it + 7]) }
would inline to the same as an imperative loopDaniele B
10/16/2020, 2:21 AMrandom access actually?ephemient
10/16/2020, 2:22 AMRuckus
10/16/2020, 2:23 AMlist[n] is constant time, not linearephemient
10/16/2020, 2:24 AMDaniele B
10/16/2020, 2:25 AMDaniele B
10/16/2020, 2:25 AMephemient
10/16/2020, 2:26 AMDaniele B
10/16/2020, 2:27 AMDaniele B
10/16/2020, 2:28 AMephemient
10/16/2020, 2:28 AMephemient
10/16/2020, 2:29 AMephemient
10/16/2020, 2:30 AMDaniele B
10/16/2020, 2:34 AMlistOf ?
List(mylist.size - 8) { myFunction(mylist[it], mylist[it + 1], mylist[it + 7]) }ephemient
10/16/2020, 2:35 AMlistOf() is backed by an ArrayList (implementation detail, but even if it changes in the future it will still work)Daniele B
10/16/2020, 2:36 AMmylist.windowed(8).map {
myFunction(it[0], it[1], it[7])
}ephemient
10/16/2020, 2:36 AMephemient
10/16/2020, 2:37 AMephemient
10/16/2020, 2:38 AMList(mylist.size - 7) to get the last window. that's what happens easily when working without the abstractionsVampire
10/16/2020, 7:14 AM