Hacker News new | comments | show | ask | jobs | submit login
My Elm learning experience (#elmlang) (blog.myviews.pl)
4 points by krzysu 9 months ago | hide | past | web | favorite | 5 comments



Simplier version of getAllCoordinates.

  coordsHelper : Int -> Int -> List (Int, Int)
  coordsHelper i size =
    if i < 0 then [] else
    List.repeat size i
    |> List.indexedMap (,)
    |> List.append (coordsHelper (i - 1) size)

  coords : Int -> List (Int, Int)
  coords dimension =
    coordsHelper (dimension-1) dimension


Thanks! Your code looks better than mine. I see I need to think more recursively with Elm.


Hi guys, this was my first technical post on my blog. Let me know how do you like it! What do you think about Elm? Or just come over for the next Elm Hack Night in Berlin :)


Yes I liked the post. I am coming to Elm from F# and liking the error messages and strictness.

If you are not worried about the order of the pairs, how about this....

  getAllCoordinates : Int -> List ( Int, Int )
  getAllCoordinates size =
    List.range 0 (size - 1)
    |> List.concatMap 
        (List.repeat size >> List.indexedMap (,))
NB: Be careful with recursion. For general purpose code where you don't know the size of the data structures you could get a stackoverflow. In that case you can refactor recursive code to maps or folds.


thanks for your comment, I like your implementation even more!




Guidelines | FAQ | Support | API | Security | Lists | Bookmarklet | Legal | Apply to YC | Contact

Search: