The last line with List.repeat doesn't feel right to me. It does the job, but only one of the checkboxes will have an XY position of (0, 0).
I completely agree, especially since you're not using the value when you use List.indexedMap. I'd probably just use List.map (\index -> ...) List.range 0 24 for building the initialstate.
I just used a tuple because I saw it in the documentation. Is there a practical difference between tuples and a list of length 2?
There's a huge difference! The best example probably being that with the tuple you can do
let(x,y)=tuplePositionin
but with a List Int you'd have to do something like
caselistPositionof[x,y]->-- use x and y_->-- handle an impossible case
For both your Svelte and Elm code, you might be interested in Manhattan distance. Using this would allow you to just check the distance between 2 points being equal to 1 and not have to check the x and y distances separately.
Maybe there's a way I could have achieved what I wanted to anyway.
There totally is a way! You could change your Msg from PressButton ( Int, Int ) to PressButton ( Int, Int ) Bool and then in your view do
You'll see that I changed from onClick to onCheck which is expecting a function that takes a Bool and returns a Msg. By doing only PressButton ( checkbox.x, checkbox.y ) I've created a function that is expecting a Bool and returns a Msg. But your solution also works great.
Can't wait to read more!
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
I completely agree, especially since you're not using the value when you use
List.indexedMap
. I'd probably just useList.map (\index -> ...) List.range 0 24
for building the initialstate.There's a huge difference! The best example probably being that with the tuple you can do
but with a
List Int
you'd have to do something likeFor both your Svelte and Elm code, you might be interested in Manhattan distance. Using this would allow you to just check the distance between 2 points being equal to 1 and not have to check the x and y distances separately.
There totally is a way! You could change your
Msg
fromPressButton ( Int, Int )
toPressButton ( Int, Int ) Bool
and then in your view doYou'll see that I changed from
onClick
toonCheck
which is expecting a function that takes aBool
and returns aMsg
. By doing onlyPressButton ( checkbox.x, checkbox.y )
I've created a function that is expecting aBool
and returns aMsg
. But your solution also works great.Can't wait to read more!