I would only introduce something like the createModelWithProp1Something
function if I had the desire (or reason to believe that that desire might
later arise) to apply it to something else than defaultModel at some point.
If I knew I would only ever be going to apply createModelWithProp1Something
to defaultModel, then I would not introduce createModelWithProp1Something
separately and apply it to defaultModel to get myModelWithSomething.
Instead I would directly define myModelWithSomething as { defaultModel |
prop1 = "Something" }.
​

2016-08-26 13:45 GMT+02:00 Francisco Ramos <[email protected]>:

> Hi Janis,
>
> Thanks for the explanation. Would you do something like that or you'd
> rather pass the defaultModel into the function?
>
> createModelWithProp1Something model: Model
> createModelWithProp1Something =
>   { model | prop1 = "Something" }
>
> -- Somewhere else
>
> let
>   myModelWithSomething = createModelWithProp1Something defaultModel
> in
>   -- ...
>
> I guess, based on your answer, both are correct
>
> Thanks,
>
> Fran
>
>
> On Friday, August 26, 2016 at 9:10:59 AM UTC+2, Janis Voigtländer wrote:
>>
>> What you are doing there is absolutely fine. Functional programming is
>> about values and functions. In your example you define some values based on
>> other values (without modifying the original values, of course). No reason
>> to feel “that it goes against pure functions”. It does not.
>> ​
>>
>> 2016-08-26 8:55 GMT+02:00 Francisco Ramos <[email protected]>:
>>
>>> Hi there,
>>>
>>> I'm fairly new in Functional Programming and Elm language and I was
>>> hoping someone could tell me if what I'm doing is correct or it goes
>>> against Elm and its pure functions. I have a model, defaultModel, with some
>>> values by default. I have a couple functions that create a new model using
>>> defaultModel as a template, but I'm not passing this model, which makes me
>>> doubt about the correct use of pure functions. Let's have a look at this
>>> with an example:
>>>
>>> type alias Model =
>>>   { prop1 : String
>>>   , prop2 : Int
>>>   , prop3 : Bool
>>>   }
>>>
>>> defaultModel : Model
>>> defaultModel =
>>>   { prop1 = "Test"
>>>   , prop2 = 5
>>>   , prop3 = True
>>>   }
>>>
>>>
>>>
>>> createModelWithProp1Something : Model
>>> createModelWithProp1Something =
>>>   { defaultModel | prop1 = "Something" }
>>>
>>>
>>> createModelWithProp2Ten : Model
>>> createModelWithProp2Ten =
>>>   { defaultModel | prop2 = 10 }
>>>
>>> createModelWithProp3False : Model
>>> createModelWithProp3False =
>>>   { defaultModel | prop3 = False }
>>>
>>> So the question is, is it correct to use this defaultModel inside these
>>> functions without passing it in?, If it's not, could anyone explain me
>>> why?. I have the feeling that it goes against pure functions, but I'm
>>> thinking, defaultModel won't ever be mutated, so no risk of side effects.
>>>
>>> Thanks a lot in advance
>>>
>>> Fran
>>>
>>> --
>>> 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.
>

-- 
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.

Reply via email to