Kembali ke Perpustakaan
Region:
Switch to EN
Menengah Exercism • elixir
Ranges
Ringkasan Pelajaran
# Introduction
About
Ranges represent a sequence of one or many consecutive integers. They:
- Are created using the
..operator and can be both ascending or descending. - Their default step is
1, but can be modified using the..//operator (since Elixir 1.12). - Are inclusive of the first and last values.
- Implement the Enumerable protocol.
- Are represented internally as a struct, but can be pattern matched using
... - Can be used with integers written in the binary, octal, hexadecimal, and code point notation.
- Can be turned into lists with functions such as
Enum.to_list/1orEnum.map/2.
Enum.to_list(9..1)
# => [9, 8, 7, 6, 5, 4, 3, 2, 1]
Enum.map(?A..?F, &<<&1>>)
["A", "B", "C", "D", "E", "F"]
Originally from Exercism elixir concepts