Record map syntax

It might be a good idea to add a syntax for applying a function to a record field. For example, this would increase the amount field by 1:

{ record | amount <- (+) 1 }

Currently it would have to be done like this which is too repetitive:

{ record | amount = 1 + record.amount }

I’m not sure how often this would be useful. I have found 2 examples in the source code of my EditSC project where this would be useful. Currently they look similar to this:

{ model | someList = newItem :: model.someList }
{ model | someArray = Array.set index newValue model.someArray }

It could look like this instead:

{ model | someList <- (::) newItem }
{ model | someArray <- Array.set index newValue }

I think it is easier for something to be changed/removed from the language than to add a new syntax. The last time it occurred was in Nov 2016 at 0.18 release, when primes, interpolation and backticks were removed. Elm simplicity gives us some benefits, such as ease of learn and compiler speed.

3 Likes

Yeah, programming languages with too many features absolutely suck. I keep on forgetting the enum syntax in typescript (googled it just now)

2 Likes

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.