Skip to content

Recursive objects amending with spread operator #505

Answered by HT154
germanosin asked this question in Q&A
Discussion options

You must be logged in to vote

I ran across this myself a few weeks ago! Not only is this expected, but it's a gateway to one of the language's more advanced features: Mixins.

Using the spread operator like you have does not perform a "deep" amend, it only replaces the keys in source with the keys that exist in another, which explains why the output for merged looks the way it does.

A Mixin<Dynamic> is sugar for Function1<Dynamic, Dynamic>, or a function that accepts a Dynamic, transforms it, and returns the result. Creating a Mixin looks very similar to creating a regular value:

another: Mixin<Dynamic> = new {
    spring {
        test {
            name = "True"
        }
    }
}

Integrated into your example code, it…

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by germanosin
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants