Thanks again Peter, and don't worry! You helped me a lot! I added your 
solution like this :

let
              currentBox = List.concat model.cells
                            |> List.filter (\box -> box.id == boxId)  
                            |> List.head
                            |> Maybe.withDefault (Box -1 Nothing)
              
              updateRow row =
                let
                  updateBox box =   
                    if boxId == box.id then
                      {box | player = Just model.current}
                    else
                      box
                in
                  List.map updateBox row
            in
            case currentBox.player of
              Nothing ->
                ({model | cells = List.map updateRow model.cells, current = 
changePlayer model.current, boxClicked = Just boxId}, Cmd.none)
              Just _ ->
                (model, Cmd.none)

and it worked! Now, I'm asking one question : are all these stuffs on 
manipulating lists (concat, map and so on) and immutability more efficient 
than traditionnal OOP?

Thanks again!

Le jeudi 27 octobre 2016 13:56:47 UTC+2, Peter Damoc a écrit :
>
> Maybe is used to wrap an operation that might fail. 
> So, when you ask for the head of a list, you might get Just the head OR 
> you might get Nothing if the list is empty. 
>
> However, the issue here is again, an error on my part. Sorry about that. 
>
 

>
> The actual solution to the currentBox is:  
>
> currentBox = 
>     List.concat model.cells
>     |> List.filter (\box -> box.id == boxId)  
>     |> List.head
>     |> Maybe.withDefault (Box -1 Nothing) -- this value should never 
> happen in your context
>
>
> You don't need to filter each row, you need to concatenate the rows into a 
> single list and filter that list on the id of the box. 
>
> Sorry about the misleading code from the previous message (I should have 
> tested it but was too lazy). 
>
>
> -- 
> There is NO FATE, we are the creators.
> blog: http://damoc.ro/
>

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