https://kotlinlang.org logo
#stdlib
Title
# stdlib
i

ilya.gorbunov

09/05/2018, 11:41 AM
Hi everyone, we'd like to know your opinion on renaming the
buildSequence
and
buildIterator
functions. Please share your thoughts regarding the names proposed in the attached post, especially if you find something confusing about any of them.
r

robin

09/05/2018, 3:07 PM
I don't like the
defineSequence
name. I think the lazy nature of Sequence should be enough to convey that, and the other two names are more easy to find via auto-complete without remembering the exact word that comes before "sequence", which is something that always annoys me with the current names, especially having a
buildSequence
and a
generateSequence
and having to remember which prefix it was for which use case. I don't have a clear preference for either of the other two names,
sequence
is nice and DSL-like, but I see the name overload issue, and
sequenceFrom
has a nice duality to
sequenceOf
, where the latter creates a sequence of some values, and the former creates a sequence from a lambda you give it.
1
g

gaetan

09/05/2018, 9:39 PM
I find
sequence
and
defineSequence
names too static for such a function. I really like the
sequenceFrom
which gives a good idea of what is going to happen: the values of the sequence are going to come from the given suspending lambda.
1
n

nkiesel

09/06/2018, 1:13 AM
My vote would be for
sequenceFrom
1
k

kingsley

09/06/2018, 7:57 AM
I would go with
sequenceFrom
as well. In addition to the comments, I think it has a familiar connotation to it. For instance, it could be a clear differentiator between
mapOf
,
listOf
, etc, which are eager and
sequenceFrom
, etc which would be lazy
👍 1
v

voddan

09/06/2018, 1:14 PM
It's a pity that
Sequence {}
and
buildSequence {}
do almost the same thing, but have to have different names. Could we somehow capitalize on the analogy with
asyncSequence
or
suspendSequence
?
i

ilya.gorbunov

09/06/2018, 1:22 PM
Sequence { }
and
buildSequence { }
are inherently different, the former is a SAM-constructor for the single abstract method interface
Sequence
.
v

voddan

09/06/2018, 1:25 PM
@ilya.gorbunov are we talking about the same function http://kotlinlang.org/api/latest/jvm/stdlib/kotlin.sequences/-sequence.html ?
i

ilya.gorbunov

09/06/2018, 1:45 PM
Yes
v

voddan

09/06/2018, 2:23 PM
Well then, from a user's point of view, you pass a lambda to both functions and get a sequence of values that are produced by the said lambda. All other differences are in the implementation (suspend / non-suspend) , no?
r

robin

09/06/2018, 2:24 PM
Well the big difference is that one of those lambdas is just lazily producing the source of the sequence, and the other one is the source itself
v

voddan

09/06/2018, 2:31 PM
Oh, I see.
iterator: () -> Iterator<T>
produces an iterator. That is unfortunate. Must agree with @ilya.gorbunov then. Sorry for the confusion
c

Czar

09/07/2018, 9:10 PM
sequence
or
sequenceFrom
i

ilya.gorbunov

09/12/2018, 2:36 PM