New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Configuration closures keypath #3
Comments
Hi, yes you could achieve this with custom operators and function builders. Here is the code for the function builder part : (From https://twitter.com/v_pradeilles/status/1138555570980626432/) Then, you just need to define a custom operator that returns a |
Complex but beautiful! |
Thank you @astrokin i have already used the example provided in
|
you can achieve it this way too https://gist.github.com/nicklockwood/9b4aac87e7f88c80e932ba3c843252df |
My actual implementation is almost identical to with function @astrokin |
@vincent-pradeilles i have been usign the code you provided to achieve, for first, the DSL like syntax in order to be able to write
However, this doesnt compile. It does until the instruction is one, but not with multi line assignments, complaining is not possible to infer the T type. I have checked the syntax hundreds of time, and i understood most of the code which is being used. As workaround to make compiler happy, i ve been using the following syntax:
but as you can see, it required explicit call to buildBlock function and comma separation between instructions. Im pretty sure this is the purpose of @_functionBuilder, which is identical to your code:
What is wrong? |
That's indeed very weird! The code I gave you was from the Xcode 11 beta, and now it seems that on current versions it's not working anymore. For the moment I don't have an explanation as to why it no longer works. |
Hello Vincent, this repo is so useful if you are interested about keypaths.
I have been digging into the argument for the past weeks, but i still cant master the topic as i would like to.
Supposing you have a function to customize an object by using a closure:
using it, will result in something like:
Although useful, i was wondering if keypaths could help making the syntax more concise.
Would be possible to achieve something like this?
#07 Implementing the builder pattern with keypaths
This section is absolutely interesting, and is very close to my concept of clean and concise syntax.
The text was updated successfully, but these errors were encountered: