Hi everyone, we'd like to know your opinion on ren...
# stdlib
i
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
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
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
My vote would be for
sequenceFrom
1
k
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
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
Sequence { }
and
buildSequence { }
are inherently different, the former is a SAM-constructor for the single abstract method interface
Sequence
.
v
@ilya.gorbunov are we talking about the same function http://kotlinlang.org/api/latest/jvm/stdlib/kotlin.sequences/-sequence.html ?
i
Yes
v
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
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
Oh, I see.
iterator: () -> Iterator<T>
produces an iterator. That is unfortunate. Must agree with @ilya.gorbunov then. Sorry for the confusion
c
sequence
or
sequenceFrom
i