mirror of
https://github.com/jbranchaud/til
synced 2026-01-04 15:48:01 +00:00
Add Range Into List Using Comprehensions as an elixir til
This commit is contained in:
13
elixir/range-into-list-using-comprehensions.md
Normal file
13
elixir/range-into-list-using-comprehensions.md
Normal file
@@ -0,0 +1,13 @@
|
||||
# Range Into List Using Comprehensions
|
||||
|
||||
Using an _identity_ comprehension and the `:into` option, we can easily
|
||||
convert a range into a list.
|
||||
|
||||
```elixir
|
||||
> for x <- 1..10, into: [], do: x
|
||||
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
|
||||
```
|
||||
|
||||
Check out [the docs for the `:into`
|
||||
option](http://elixir-lang.org/getting-started/comprehensions.html#the-into-option)
|
||||
for more details.
|
||||
Reference in New Issue
Block a user