[elm-discuss] Re: Naming functions

2016-10-24 Thread Lars Jacobsson
Ok Max, thanks I'll give it a go and see how it works out.

On Monday, October 24, 2016 at 4:13:33 PM UTC+2, Max Goldstein wrote:
>
> If you're going to refer to items by ID a lot, you should probably use a 
> dictionary keyed on ID. Assuming items is a record with an id field:
>
> { model |
> items = model.items |> Dict.insert updatedItem.id updatedItem }
>

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


[elm-discuss] Re: Naming functions

2016-10-24 Thread Max Goldstein
If you're going to refer to items by ID a lot, you should probably use a 
dictionary keyed on ID. Assuming items is a record with an id field:

{ model |
items = model.items |> Dict.insert updatedItem.id updatedItem }

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


[elm-discuss] Re: Naming functions

2016-10-24 Thread Lars Jacobsson
| The names were inspired by Dict.insert and Dict.update, which were the 
closest to what I was looking for.

Yeah, I'm probably just too used to that dot notation.


I don't know why but
items.replaceItemById id item
looks better than
replaceItemById items id item
. Somehow it feels like a standalone function named "replaceItemById" won't 
give us a list in return. But taking your idea to heart this would then be 
something like itemsUpdateById

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


[elm-discuss] Re: Naming functions

2016-10-24 Thread Wouter In t Velt
Op maandag 24 oktober 2016 13:18:59 UTC+2 schreef Lars Jacobsson:
>
> Any thinking going out there on around naming conventions OOP vs 
> functional? I'd be grateful for any input on this matter of life or death!
>

I always try to keep my naming conventions close to the Core functions.
E.g. in my Elm app, I have functions similar to yours. They are called 
listUpdate and listInsert with the following signatures:

listUpdate : Int -> (RecordWithID a -> RecordWithID a) -> List (RecordWithID 
a) -> List (RecordWithID a)
listUpdate index updatefunction list =

listInsert : Int -> RecordWithID a -> List (RecordWithID a) -> List (
RecordWithID a)
listInsert index newRecord list =

type alias RecordWithID a = { a | id : Int }

The names were inspired by Dict.insert and Dict.update, which were the 
closest to what I was looking for.

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