Our codebase suffers from this as well. And unlike what one of the follow ups
noted, this isn't an issue of wanting to add fields. Rather, it's an issue of
not being able to use an expression in the first part of the record update. In
this case, one doesn't even need a general expression but just an imported
value. On the their hand, members of my team have gotten bit by and complained
about not being able to construct a nested update using what they thought were
the language constructs:
newFoo = { oldFoo | nested = { oldFoo.nested | field = 3 } }
The "best" syntax I've seen for that is something like:
newFoo =
3 |> asFieldIn oldFoo.nested |> asNestedIn oldFoo
But that's pretty obscure as well.
That said, I just added a utility module to our project that is filled with
generic setFoo and asFooIn functions for every field name that seems at all
likely to be used more than once. I would love to have support for .field=
functions to parallel the .field functions. I would have them take the assigned
value as a first parameter and the record as a second parameter to enable
writing:
Slides.defaultConfig
|> .someAttribute= myCustomValue
The case where the parameters are reversed which helps with nesting could be
handled using a utility function:
3
|> into oldFoo.nested .field=
|> into oldFoo .nested=
Mark
> On Mar 2, 2017, at 10:16 PM, Richard Feldman <[email protected]>
> wrote:
>
> Re-posting the first example from Franscisco's thread:
>
> There is a common pattern where a library (ex, elm-markdown) will provide a
> default config, to be extended by the user.
>
> Here the two ways to do this right now, one painfully verbose and the other
> relying on exposing values that would read better if fully qualified instead
> of exposed:
>
> import Slides
>
> slidesDefaultConfig =
> Slides.defaultConfig
>
> myCustomSlidesConfig =
> { slidesDefaultConfig | someAttribute = myCustomvalue }
>
> or
>
> import Slides exposing (slidesDefaultConfig)
>
> myCustomSlidesConfig =
> { slidesDefaultConfig | someAttribute = myCustomvalue }
>
> Not a big deal TBH, but annoying.
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Elm Discuss" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "Elm
Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.