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