Allow referencing of the original object inside a with
expression
#9057
Unanswered
devmattr
asked this question in
Language Ideas
Replies: 2 comments 5 replies
-
What's wrong with just storing it in a local variable? That's what the compiler would have to do in order to allow what you're suggesting. |
Beta Was this translation helpful? Give feedback.
3 replies
-
I think this generalizes to piping essentially. GetClass(classId) |> (@class => @class with { Students = @class.Students.Add(newStudent) }) |> UpdateClass Depending on your relationship with C# you could do something like the following, though some may consider it abusive. GetClass(classId)
.Apply(Class.AddStudent.Apply(newStudent))
.Apply(UpdateClass); |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Quick and simple, in case it's a silly idea.
Here i've used the imagined '
original
' keyword to illustrate what I want.I can't see a way currently to do this operation without first storing the result of
GetClass(classId)
on a separate line.Edit:
One problem with the above is it requires a new keyword (and I dont think you could recycle an existing one).
Perhaps some mechanism to define an inline variable that is filled with the original.
Eg:
GetClass(classId) with (original) { Students = original.Students.Add(newStudent) }
Where
original
would be scoped just to the inside of the following object initializer. (i'm not a fan of how other inlining var declarations have nonintuitive scope and can 'leak' into subsequent operations where they aren't needed)Beta Was this translation helpful? Give feedback.
All reactions