Giter VIP home page Giter VIP logo

Comments (7)

juanchosaravia avatar juanchosaravia commented on May 25, 2024 4

Juan thanks for the feedback! It's an interesting point! To be honest I need to think about to add this feature as I'm not 100% sure if this could bring other confusions on how to use Collections. Still feel free to send a PR, I think will be a great starting point to review it in more details.

from autodsl.

apatrida avatar apatrida commented on May 25, 2024 3

This style is how I do my builders, no need for the +, just the function call adds to its owner's collection.

from autodsl.

Juan-EBI avatar Juan-EBI commented on May 25, 2024 1

Hey something like this (list is mutable to keep example short)

data class Person(
    var name: String? = null,
    var age: Int? = null,
    var friends: MutableList<Person> = mutableListOf())

fun person(body: Person.() -> Unit) = Person().apply(body)
fun Person.friends(body: MutableList<Person>.() -> Unit) = body(friends)
fun MutableList<Person>.person(body: Person.() -> Unit) = add(Person().apply(body))

fun main(args: Array<String>) {
    val me = person {
        name = "Juan"
        age = 29

        friends {

            person {
                name = "Jhon"
                age = 31
            }

            person {
                name = "David"
                age = 31
            }
        }
    }

    println(me.toString())
}

from autodsl.

juanchosaravia avatar juanchosaravia commented on May 25, 2024

Hi Juan!
Interesting, I'm curious how are you achieving to add each person in the list with this syntax. Can you share the code here so I can see how did you do it? Specially the signature of the friends context to be able to add each "person".

from autodsl.

Juan-EBI avatar Juan-EBI commented on May 25, 2024

If you consider it good and give me some context about expected changes I can submit a pr for this

from autodsl.

manosbatsis avatar manosbatsis commented on May 25, 2024

+1 from me, the + only adds confusion at best IMHO. I tend to use the same style with @apatrida e.g. in vaultaire

from autodsl.

cee-dee avatar cee-dee commented on May 25, 2024

I agree, would be nice to work without +!

from autodsl.

Related Issues (10)

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.