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 <jscriptco...@gmail.com>:

> 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 elm-discuss+unsubscr...@googlegroups.com.
> 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 elm-discuss+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to