Skip to content

Instantly share code, notes, and snippets.

@valmat
Created November 14, 2016 17:32
Show Gist options
  • Save valmat/dfde28138a143f4e339eb79233a887ea to your computer and use it in GitHub Desktop.
Save valmat/dfde28138a143f4e339eb79233a887ea to your computer and use it in GitHub Desktop.
try haskell
join :: Char -> [String] -> String
join _ [] = []
join _ [s] = s
join gl arr =
head arr ++ gl : joingl (tail arr)
where
joingl = join gl
putStrLn (join ':' ["str1", "str2", "str3"])
-- (List, Last, Tail)
type HlprSplTp = ([String], String, String)
splitHlpr :: Char -> HlprSplTp -> HlprSplTp
splitHlpr c (arr, [], []) = (
arr ++ [[]],
[],
[]
)
splitHlpr c (arr, lst, []) = (
arr ++ [lst],
[],
[]
)
splitHlpr c (arr, lst, tl) =
if head tl == c
then splitHlpr c (
arr ++ [lst],
[],
tail tl
)
else splitHlpr c (
arr,
lst ++ [head tl],
tail tl
)
split :: Char -> String -> [String]
split _ [] = []
split s [c] = if s == c then [[],[]] else [[c]]
split c str =
let
(arr, _, _) = splitHlpr c ([],[], str)
in
arr
print (split ':' "str1:str2:str3")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment