mirror of
https://github.com/jbranchaud/til
synced 2026-01-03 15:18:01 +00:00
Add Range Into List Using Comprehensions as an elixir til
This commit is contained in:
@@ -7,7 +7,7 @@ variety of languages and technologies. These are things that don't really
|
||||
warrant a full blog post. These are mostly things I learn by pairing with
|
||||
smart people at [Hashrocket](http://hashrocket.com/).
|
||||
|
||||
_490 TILs and counting..._
|
||||
_491 TILs and counting..._
|
||||
|
||||
---
|
||||
|
||||
@@ -99,6 +99,7 @@ _490 TILs and counting..._
|
||||
- [List Functions For A Module](elixir/list-functions-for-a-module.md)
|
||||
- [Pattern Matching In Anonymous Functions](elixir/pattern-matching-in-anonymous-functions.md)
|
||||
- [Quitting IEx](elixir/quitting-iex.md)
|
||||
- [Range Into List Using Comprehensions](elixir/range-into-list-using-comprehensions.md)
|
||||
- [Replace Duplicates In A Keyword List](elixir/replace-duplicates-in-a-keyword-list.md)
|
||||
- [Requiring Keys For Structs](elixir/requiring-keys-for-structs.md)
|
||||
- [Reversing A List](elixir/reversing-a-list.md)
|
||||
|
||||
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