ilya.gorbunov

    ilya.gorbunov

    4 years ago
    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.
    robin

    robin

    4 years ago
    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.
    gaetan

    gaetan

    4 years ago
    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.
    n

    nkiesel

    4 years ago
    My vote would be for
    sequenceFrom
    k

    kingsley

    4 years ago
    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
    voddan

    voddan

    4 years ago
    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
    ?
    ilya.gorbunov

    ilya.gorbunov

    4 years ago
    Sequence { }
    and
    buildSequence { }
    are inherently different, the former is a SAM-constructor for the single abstract method interface
    Sequence
    .
    voddan

    voddan

    4 years ago
    @ilya.gorbunov are we talking about the same function http://kotlinlang.org/api/latest/jvm/stdlib/kotlin.sequences/-sequence.html ?
    ilya.gorbunov

    ilya.gorbunov

    4 years ago
    Yes
    voddan

    voddan

    4 years ago
    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?
    robin

    robin

    4 years ago
    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
    voddan

    voddan

    4 years ago
    Oh, I see.
    iterator: () -> Iterator<T>
    produces an iterator. That is unfortunate. Must agree with @ilya.gorbunov then. Sorry for the confusion
    Czar

    Czar

    4 years ago
    sequence
    or
    sequenceFrom
    ilya.gorbunov

    ilya.gorbunov

    4 years ago