Bala
Bala

Reputation: 11274

How do I pipe a single number to get a list?

I have a single element/number that I am piping to Enum.into([]) but Elixir throws ** (Protocol.UndefinedError) protocol Enumerable not implemented for 90

90 |> Enum.into([])

v = 65
v |> Enum.into([]) Enumerable not implemented for 65

Upvotes: 5

Views: 1021

Answers (2)

IT'S ME
IT'S ME

Reputation: 1

iex(1)> n = [1]

[1]

iex(2)> Enum.into(n, [ ])  
[1]

iex(3)> n |> Enum.into([ ])  
[1]

Upvotes: -1

coderVishal
coderVishal

Reputation: 9109

Enum.into/2 expects an Enumerable as the first argument, hence the error.

To pipe a Single Element into a list, use List.wrap

65 |> List.wrap

Upvotes: 10

Related Questions