Skip to content

Instantly share code, notes, and snippets.

@jpierson
Last active August 2, 2017 03:38
Show Gist options
  • Select an option

  • Save jpierson/88a1be40c2a3eab83d2d271f78293ed6 to your computer and use it in GitHub Desktop.

Select an option

Save jpierson/88a1be40c2a3eab83d2d271f78293ed6 to your computer and use it in GitHub Desktop.
Experimentation with the Elm language

Elm experiments

Lists

Join a list of strings into a single string with specified separator

import Html exposing (text)

v = [1,2,3]

joinHelper : String -> List String -> String -> String
joinHelper separator list s = 
  case list of
    [] -> s
--    [a] -> s ++ a
    h::t -> joinHelper separator t (s ++ separator ++ h)

join : String -> List String -> String
join separator list = 
  case list of 
    [] -> ""
    h::t -> joinHelper separator t h

main =
  text (toString (join "::" (List.map (\i -> toString i) v)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment