Repeat a string: Difference between revisions

Added Erlang version
m (Simplified 'need' call)
(Added Erlang version)
Line 234:
=={{header|E}}==
<lang e>"ha" * 5</lang>
 
=={{header|Erlang}}==
This example uses list comprehensions to accumulate N copies of X:
<lang erlang>
repeat(X,N) ->
lists:flatten([ X || _ <- lists:seq(1,N)]).
</lang>
This example uses lists:flatmap to do the same:
<lang erlang>
repeat(X,N) ->
lists:flatmap(fun (_) -> X end, lists:seq(1,N)).
</lang>
 
The first version also works for characters or any other values (though deeplists will all be flattened). The second version requires that X be a list, anything else will result in a bad argument exception.
 
=={{header|Factor}}==
Anonymous user