Hi Matthieu, your function is genius, https://ellie-app.com/4qBxgmzvBa1/0

Thanks a lot. I couldn't come up with a good way to implement this. Not
only that, but also I've just learnt something I didn't even know was
possible in Elm, the definition of a helper function in the "let" block.
Never saw that before. I'm fairly new in Elm. Thanks for that also :-)

Fran

On Mon, Dec 4, 2017 at 10:02 AM Matthieu Pizenberg <
[email protected]> wrote:

>
> I wouldn't want to go through hundreds of thousands for just one thousand.
>> That's why I'm trying to come up with a function that have the behavior I
>> described initially, "nextlocation". Along with "index" function I can work
>> out in O(1) the index for the next one
>
>
> Yep sorry, I didn't realize that initially. Then you could do something
> like:
>
> nextLocation : Location -> Shape -> Maybe Location
> nextLocation location shape =
>     let
>         increment (loc, size) (locationAcc, shouldInc) =
>             if shouldInc then
>                 if loc + 1 < size then
>                     ( loc + 1 :: locationAcc, False )
>                 else
>                     ( 0 :: locationAcc, True )
>             else
>                 ( loc :: locationAcc, False )
>
>         newLocation =
>             List.map2 (,) location shape
>                 |> List.foldr increment ([],True)
>     in
>     if Tuple.second newLocation then
>         Nothing
>     else
>         Tuple.first newLocation
>
>
> --
> 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.
>

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