Last active
August 2, 2017 03:38
-
-
Save jpierson/88a1be40c2a3eab83d2d271f78293ed6 to your computer and use it in GitHub Desktop.
Revisions
-
jpierson revised this gist
Aug 2, 2017 . 1 changed file with 31 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -48,4 +48,34 @@ join prefix separator suffix list = main = text (toString (join "<<<" "::" ">>>" (List.map (\i -> toString i) v))) ``` Outputs the text `<<<1::2::3>>>` ### Join items of a list using generic function using specified prefix, separator, and suffix ```elm import Html exposing (text) v = ['a', 'b', 'c'] joinHelper : (a -> a -> a) -> a -> a -> List a -> a -> a joinHelper append separator suffix list s = case list of [] -> append s suffixstrings h::t -> joinHelper append separator suffix t (append s (append separator h)) join : (a -> a -> a) -> a -> a -> a -> List a -> a join append prefix separator suffix list = case list of [] -> append prefix suffix h::t -> joinHelper append separator suffix t (append prefix h) myJoinStrings = join (\ a b -> a ++ b) "<<<" "::" ">>>" main = text (toString (myJoinStrings (List.map (\c -> String.fromChar c) v))) ``` Outputs the text `<<<a::b::c>>>` -
jpierson revised this gist
Aug 2, 2017 . 1 changed file with 25 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -23,4 +23,29 @@ join separator list = main = text (toString (join "::" (List.map (\i -> toString i) v))) ``` Outputs the text `1::2::3` ### Join a list of strings into a single string with specified separator, prefix and suffix ```elm import Html exposing (text) v = [1,2,3] joinHelper : String -> String -> List String -> String -> String joinHelper separator suffix list s = case list of [] -> s ++ suffix h::t -> joinHelper separator suffix t (s ++ separator ++ h) join : String -> String -> String -> List String -> String join prefix separator suffix list = case list of [] -> "" h::t -> joinHelper separator suffix t (prefix ++ h) main = text (toString (join "<<<" "::" ">>>" (List.map (\i -> toString i) v))) ``` -
jpierson revised this gist
Aug 2, 2017 . 1 changed file with 0 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -13,7 +13,6 @@ joinHelper : String -> List String -> String -> String joinHelper separator list s = case list of [] -> s h::t -> joinHelper separator t (s ++ separator ++ h) join : String -> List String -> String -
jpierson created this gist
Aug 2, 2017 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,27 @@ # Elm experiments ## Lists ### Join a list of strings into a single string with specified separator ```elm 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))) ```