You can sort of do this with `Stream.repeatedly(fn -> :something end) |> 
Enum.take(5)`. It's a little longer, although it reads rather nicely.

On Friday, March 29, 2019 at 7:48:54 AM UTC-4, Hylke Alons wrote:
>
> Hah, this is great! thanks!
>
> On Friday, 29 March 2019 12:47:14 UTC+1, Wojtek Mach wrote:
>>
>> iex(1)> List.duplicate(:something, 5)
>> [:something, :something, :something, :something, :something]
>>
>> :-)
>>
>> Hi there,
>>>
>>> I would like to know your opinion about an `Enum.repeat/2` function. In 
>>> test, I notice often that I write:
>>>
>>> Enum.map(1..5, fn(_) ->  :something end) 
>>> [:something, :something, :something, :something, :something]
>>>
>>> or 
>>>
>>> for (_ Enter code here... <- 1..5), do: :something
>>> => [:something, :something, :something, :something, :something]
>>>
>>> As I am not interested in the value of the input, I think a 
>>> `Enum.repeat/2` function would be more efficient:
>>> Enum.repeat(5, fn -> :something end)
>>> => [:something, :something, :something, :something, :something]
>>>
>>>
>>> I am aware that `Enum.times/2` is deprecated in the past in favour of 
>>> ranges. I want to highlight that in that function, the value was passed to 
>>> the function.
>>>
>>>
>>> What is your take? Or perhaps I overlooked a function?
>>>
>>

-- 
You received this message because you are subscribed to the Google Groups 
"elixir-lang-core" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/elixir-lang-core/aee223df-0161-4c16-96e2-eb936c18d456%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to