I'm totally confused but I can't find any solution to my problem... When I 
remove List.head from the currentBox function, I can see that it returns a 
list of Nothing. So I thought I could add a List.filter function in order 
to return only the box I wanted, like this :

currentBox boxId = 
  cells
  |> List.map (filterRow boxId)
  |> List.filter (\box -> box.id == boxId)

But the compilet complains that :

(|>) is expecting the right argument to be a:

    List (Maybe Box) -> a

But the right argument is:

    List { a | id : Int } -> List { a | id : Int } 

I'm sorry but I don't understand. Since  cells |> List.map (filterRow 
boxId) returns a list, why can't I do a filter on this list? I'm not so 
familiar with Maybe, so maybe the problem is there...

Le mercredi 26 octobre 2016 14:05:34 UTC+2, Wouter In t Velt a écrit :
>
> Op woensdag 26 oktober 2016 13:36:18 UTC+2 schreef Did:
>>
>> But It seems that, in the update function, currentBox always return 
>> something because it doesn't update my model... I'm obviously doing 
>> something wrong. But, for me, as all cells are unoccupied, this test should 
>> return Nothing. What's wrong ?
>>
>
> The output of the currentBox function is not Nothing, but it is Just 
> Nothing. A bit of a strange outcome.
> If you remove the |> List.head from the currentBox function, you can see 
> where things go wrong.
>
> I'm sorry, but I don't know how to debug elm code in general, and in 
>> particular with the elm lang try editor (I'm at work and I don't have elm 
>> working on my machine...)
>>
>
> Below is a quick test I did in elm lang try editor. You can copy/paste 
> this.
> With elm, it is relatively easy to test parts of your code (because all 
> functions are "pure", so the same input always gives the same output.)
>
> import Html exposing (text)
>
> type alias Box = { id : Int, player : Maybe Int }
>
> filterRow: Int -> List Box -> Maybe Box
> filterRow boxId row =
>   row
>   |> List.filter (\box -> box.id == boxId && not (box.player == Nothing))
>   |> List.head
>
> currentBox boxId = 
>   List.map (filterRow boxId) cells
>   |> List.head
>
> cells = 
>   [ [ Box 1 Nothing, Box 2 Nothing, Box 3 Nothing ]
>   , [ Box 4 Nothing, Box 5 Nothing, Box 6 Nothing ]
>   , [ Box 9 Nothing, Box 8 Nothing, Box 9 Nothing ]
>   ]
>
> main =
>   text <| toString <| currentBox 5
>
>
>

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