list.range()

The list.range() function returns the list from the $list of range $from to $to.

// Sass.
@use 'sass:list';

// Functions.
@use 'list.nth.function' as *;

// Modules.
@use '../math';

// The `list.range()` function.
@function range($list, $from: 1, $to: list.length($list)) {
  @return nth($list, (math.range(($from, $to, 1, 0)...) or $to)...);
}

Parameters

$list

The list to retrieve the elements from range $from to $to.

$from: 1

Index from which retrieving elements begins.

$to: list.length($list)

Index where the retrieval of elements ends.

Return

The return value is the list of range $from to $to.

Examples

// Use.
@use 'angular-package/sass/list';

// Examples.
// from - to
@debug list.range(('a', 'b', 'c', 'd', 'e', 'f'), 2, 4); // "b", "c", "d"
@debug list.range(('a', 'b', 'c', 'd', 'e', 'f'), 2, -1); // "b", "a", "f"
@debug list.range(('a', 'b', 'c', 'd', 'e', 'f'), -1, 1); // "f", "a"
@debug list.range(('a', 'b', 'c', 'd', 'e', 'f'), -6, -2); // "a", "b", "c", "d", "e"
@debug list.range(('a', 'b', 'c', 'd', 'e', 'f'), 4, -4); // "d", "c", "b", "a", "f", "e", "d", "c"
@debug list.range(('a', 'b', 'c', 'd', 'e', 'f'), 4, 9); // "d", "e", "f", null, null, null
@debug list.range(('a', 'b', 'c', 'd', 'e', 'f'), -1, -2); // "f", "e"

Last updated