uhe
06/29/2017, 12:03 PM?:
is also executedmenegatti
06/29/2017, 1:18 PMmg6maciej
06/29/2017, 7:27 PMnkiesel
06/30/2017, 1:11 AMval longer = mutableListOf<Int>()
listOf(2,3,4).forEach { longer.add(it); if (it % 2 == 0) longer.add(-it) }
nkiesel
06/30/2017, 1:17 AMval longer = mutableListOf<Int>().apply { listOf(2,3,4).forEach { add(it); if (it % 2 == 0) add(-it) } }.toList()
jw
06/30/2017, 1:32 AMnkiesel
06/30/2017, 1:43 AMnkiesel
06/30/2017, 1:46 AMlistOf(2,3,4).flatMap { val l = mutableListOf(it); if (it % 2 == 0) l.add(-it); l }
gildor
06/30/2017, 2:00 AMlistOf(2, 3, 4).flatMap { item ->
List(if (item % 2 == 0) 2 else 1) {
if (it == 0) item else -item
}
}
not sure that it is readable enough, but no mutable statesnkiesel
06/30/2017, 2:03 AMflatMap
approach at least makes it clear that the lambda constructs a list of items for every item, so that is what I chose so far.ilya.gorbunov
06/30/2017, 2:14 AMflatMap { buildSequence { }}
, say flatBuild
, so that one could yield several values from lambda:
listOf(2, 3, 4).flatBuild {
yield(it)
if (it % 2 == 0) yield(-it)
}
nkiesel
06/30/2017, 2:14 AMnkiesel
06/30/2017, 2:16 AMfilter
and so hard to expand elementsgildor
06/30/2017, 2:25 AMflatMap { buildSequence { }}
actually looks nice for this case and works, you just need coroutines for that:
listOf(2, 3, 4).flatMap { buildSequence {
yield(it)
if (it % 2 == 0) yield(-it)
}.toList() }
gildor
06/30/2017, 2:26 AMsequenceOf(2, 3, 4).flatMap { buildSequence {
yield(it)
if (it % 2 == 0) yield(-it)
}}.toList()
mikehearn
07/03/2017, 3:08 PMvoddan
07/03/2017, 3:45 PMchunked
and windowed
functions.
While most of the proposal looks very solid, the pairwise
is a bit controversial. It has two major problems:
1) The naming is ambiguous since the word "pairwise" may generally be used for 3 different things. More other, the proposal uses one of its rarer meanings.
2) It is unclear why there is a need for a separate function which does the work of windowed(size = 2, step = 1)
. In addition, if a change to make step = 1
the default is adopted, that alternative changes to a short windowed(2)
, which makes pairwise
even less competitive.
In short, adding pairwise
does not seem to add a lot of value while creating an ambiguity. I believe we should exclude pairwise
at least from 1.2 to see if there is as mach demand as expected.
Here is the KEEP-11 discussion https://github.com/Kotlin/KEEP/issues/11ilya.gorbunov
07/03/2017, 3:52 PMpairwise { a, b -> }
has an advantage over windowed(2) { window -> }
that it doesn't allocate a list to represent a window. Also being a simplified case of windowed
it has an implementation more suitable to be inlined. Therefore pairwise
is inline, while windowed
is not.voddan
07/03/2017, 3:59 PMchunked(2)
then? They seem to be very symmetricalilya.gorbunov
07/03/2017, 4:05 PMchunked
. Can you?voddan
07/03/2017, 4:10 PMpairwise
for optimization purposes, then it would make sense to call it windowed2(step)
as an indication of that. That would make even more sense with a chunked2()
function, but if you say there are no use cases, I don't insist.voddan
07/03/2017, 4:12 PMilya.gorbunov
07/03/2017, 4:16 PMPair
instead of Tuple2
voddan
07/03/2017, 4:23 PMpairs()
. It shouldn't clash with anything, and it does not suggest N*N combinations. Altho it still does not make it clear if it produces overlapping pairs or notjw
07/03/2017, 4:48 PMSystem.arraycopy
call on the JVM with the same source and destination instance?jw
07/03/2017, 4:49 PMjw
07/03/2017, 4:50 PMilya.gorbunov
07/03/2017, 4:53 PMjw
07/03/2017, 4:54 PMenleur
07/07/2017, 7:25 AM