From a7e5b1d8f0c99a576c4a1ba22330f84aa6745bef Mon Sep 17 00:00:00 2001 From: jbranchaud Date: Sun, 11 Dec 2016 17:10:35 -0600 Subject: [PATCH] Add Range Into List Using Comprehensions as an elixir til --- README.md | 3 ++- elixir/range-into-list-using-comprehensions.md | 13 +++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 elixir/range-into-list-using-comprehensions.md diff --git a/README.md b/README.md index da8f847..fc16d58 100644 --- a/README.md +++ b/README.md @@ -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) diff --git a/elixir/range-into-list-using-comprehensions.md b/elixir/range-into-list-using-comprehensions.md new file mode 100644 index 0000000..71ad6f2 --- /dev/null +++ b/elixir/range-into-list-using-comprehensions.md @@ -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.