list.range()
Last updated
Was this helpful?
Last updated
Was this helpful?
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)...);
}
$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.
The return value is the list of range $from
to $to
.
// 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"
// Sass.
@use 'sass:list';
// Functions.
@use 'list.nth.function' as *;
// Modules.
@use '../math';
// Status: DONE
// The `list.range()` function returns the list from the `$list` of range `$from` to `$to`.
// @param `$list` The list to retrieve the elements from the range `$from` to `$to`.
// @param `$from` Index from which retrieving elements begins.
// @param `$to` Index where the retrieval of elements ends.
// @return The return value is the list of the given range.
@function range($list, $from: 1, $to: list.length($list)) {
@return nth($list, (math.range(($from, $to, 1, 0)...) or $to)...);
}
// from or to
// occurrence operator operand
// any/first/last '==' a, 1, true
// (any/first/last '==' a, 1, true) adjust
// Examples.
// from - to
// @debug range(('a', 'b', 'c', 'd', 'e', 'f'), 2, 4); // "b", "c", "d"
// @debug range(('a', 'b', 'c', 'd', 'e', 'f'), 2, -1); // "b", "a", "f"
// @debug range(('a', 'b', 'c', 'd', 'e', 'f'), -1, 1); // "f", "a"
// @debug range(('a', 'b', 'c', 'd', 'e', 'f'), -6, -2); // "a", "b", "c", "d", "e"
// @debug range(('a', 'b', 'c', 'd', 'e', 'f'), 4, -4); // "d", "c", "b", "a", "f", "e", "d", "c"
// @debug range(('a', 'b', 'c', 'd', 'e', 'f'), 4, 9); // "d", "e", "f", null, null, null
// @debug range(('a', 'b', 'c', 'd', 'e', 'f'), -1, -2); // "f", "e"
// from: number - to: string TODO: ?
// @debug range(('a', 'b', 'c', 'd', 'e', 'f'), -4, length); // "c", "d", "e", "f", "a", "b", "c", "d", "e", "f"
// @debug range(('a', 'b', 'c', 'd', 'e', 'f'), -4, last); // "c", "d", "e", "f", "a", "b", "c", "d", "e", "f"
// from: string to to: number
// TODO: ?
// @debug range(('a', 'b', 'c', 'd', 'e', 'f'), length, -4); // "f", "e", "d", "c", "b", "a", "f", "e", "d", "c"
// @debug range(('a', 'b', 'c', 'd', 'e', 'f'), first, -4); // "a", "f", "e", "d", "c"
// @debug range(('a', 'b', 'c', 'd', 'e', 'f'), start, -4); // "a", "f", "e", "d", "c"
// search index TODO: ?
// $-number: (1, '49 bold', 432, 313, 43, 132, 423, 89, 127, 2, 4, '213');
// @debug range($-number, first '>' 400, any '==' 127); // 432, 313, 43, 132, 423, 89, 127
// @debug range($-number, any '~=' '49', any '==' 127); // "49 bold", 432, 313, 43, 132, 423, 89, 127
// @debug range($-number, any '>' 400, any ':==' string); // 432, "49 bold"
// search index and adjust position TODO: ?
// @debug range(('a', 'b', 'c', 'd', '.', 'e', '.', 'f'), any '==' '.', 8); // ".", "e", ".", "f"
// @debug range(('a', 'b', 'c', 'd', '.', 'e', '.', 'f'), 1, any '==' '.'); // "a", "b", "c", "d", "."
// @debug range(('a', 'b', 'c', 'd', '.', 'e', '.', 'f'), 1, first '==' '.'); // "a", "b", "c", "d", "."
// @debug range(('a', 'b', 'c', 'd', '.', 'e', '.', 'f'), any '==' 'b', any '==' '.'); // "b", "c", "d", "."
// @debug range(('a', 'bold king purple', 'c', 'd', '.', 'e', '.', 'f'), any '~=' 'bold king', any '==' '.'); // "bold king purple", "c", "d", "."
// search index and adjust position TODO: ?
// @debug range(('a', 'b', 'c', 'd', '.', 'e', '.', 'f'), 1, (any '==' '.') -1); // "a", "b", "c", "d"
// @debug range(('a', 'bold king purple', 'c', 'd', '.', 'e', '.', 'f'), (any '~=' 'bold king') 1, any '==' '.'); // "c", "d", "."
// @debug range(('a', 'b', (a: 1), 'c', 'd', '.', 'e', '.', 'f'), (first ':==' map) -1, (any '==' '.') -1); // "b", (a: 1), "c", "d"