Comments (7)
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.
This style is how I do my builders, no need for the +, just the function call adds to its owner's collection.
from autodsl.
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.
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.
If you consider it good and give me some context about expected changes I can submit a pr for this
from autodsl.
+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.
I agree, would be nice to work without +
!
from autodsl.
Related Issues (10)
- Not nullable property with default value will not work HOT 1
- Compile-time check for required value HOT 2
- Problem with nested class HOT 1
- about selead class HOT 2
- Publish library into Maven Central HOT 1
- Support Mixins(?) HOT 6
- Android Sample App: compilation fails with latest Kotlin and Gradle version HOT 4
- Any plans to support kotlin multiplatform HOT 1
- I found this wonderful thing, but it can't be used. Is it really impossible to use it in 1.4x HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from autodsl.