Coder Social home page Coder Social logo

Comments (8)

JakeWharton avatar JakeWharton commented on July 4, 2024 2

from android-ktx.

JakeWharton avatar JakeWharton commented on July 4, 2024 1

from android-ktx.

JakeWharton avatar JakeWharton commented on July 4, 2024

Yeah we used to have something like this until we switched to operator fun iterator(). It's a shame there isn't a structural typing such that all the existing collection extensions could apply. Is there any reason to expose a List rather than an Iterable?

from android-ktx.

quiro91 avatar quiro91 commented on July 4, 2024

Honestly no, I agree that Iterable seems more appropriate. Will change the title of the issue

from android-ktx.

kevinmost avatar kevinmost commented on July 4, 2024

Any thoughts on it being a Sequence instead? This is what we implemented in our project, I'm not sure if the laziness of a sequence is more or less desirable though.

/**
 * Returns a [Sequence] that iterates through the children of this view
 */
val ViewGroup.children: Sequence<View>
    get() {
        var currentIndex = -1
        return generateSequence {
            currentIndex++
            getChildAt(currentIndex)
        }
    }

from android-ktx.

mokkun avatar mokkun commented on July 4, 2024

IMHO it should always return a Iterable. If you need it as a sequence you could always do myView.children.asSequence().

from android-ktx.

kevinmost avatar kevinmost commented on July 4, 2024

It seems equally simple, as Jake said, to convert between Iterable and Sequence. I personally like how, if you provide it as a Sequence, doing something like children.filterIsInstance<FooView>().map { it.foo() }.first() is lazily evaluated by default, without having to remember to convert it to a Sequence first.

from android-ktx.

JakeWharton avatar JakeWharton commented on July 4, 2024

Was merged.

from android-ktx.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.