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