I want a Elixir function to generate a list of n
occurrences of an argument, similar to Haskell's replicate
function:
Input: replicate 3 5
Output: [5,5,5]
Input: replicate 5 "aa"
Output: ["aa","aa","aa","aa","aa"]
Input: replicate 5 'a'
Output: "aaaaa"
I have made a function to "replicate" an Integer n
times:
import String
def replicate(number, n)
String.duplicate(to_string(number), n)
|> split("", trim: true)
|> Enum.map(fn n -> String.to_integer(n) end
end
But that's doesn't match the specification :( . Could you help me?