list.from()

The list.from() function returns the list of elements from index $from to the end of $list.

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

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

// Modules.
@use '../number';

// The `list.from()` function.
@function from($list, $from) {
  $result: nth($list, number.range($from, list.length($list)) or $from...);
  @return if(
    $from <= list.length($list),
    if(list.length($list) == $from, ($result,), $result),
    null
  );
}
https://github.com/angular-package/sass/blob/main/list/_list.from.function.scss
// Sass.
@use 'sass:list';

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

// Modules.
@use '../number';

// Status: DONE
// The `list.from()` function returns the list of elements from index `$from` to the end of `$list`.
// @param `$list` The list from which the elements are picked.
// @param `$from` A number-type element index of `$list`.
// @return The return value is the list of elements from index `$from` to the last index of `$list`.
@function from($list, $from) {
  $result: nth($list, number.range($from, list.length($list)) or $from...);
  @return if(
    $from <= list.length($list),
    if(list.length($list) == $from, ($result,), $result),
    null
  );
}

// Examples.
// @debug from((('a', 'b', 'c'),), 1); // (('a', 'b', 'c'),)

// @debug from((('a', 'b', 'c'), 'a', 'b', c, d, 2, 4, 5, (a: 1)), 0); // ("a", "b", "c"), "a", "b", c, d, 2, 4, 5, (a: 1)
// @debug from((('a', 'b', 'c'), 'a', 'b', c, d, 2, 4, 5, (a: 1)), -1); // (a: 1), ("a", "b", "c"), "a", "b", c, d, 2, 4, 5, (a: 1)
// @debug from((('a', 'b', 'c'), 'a', 'b', c, d, 2, 4, 5, (a: 1)), 1); // ("a", "b", "c"), "a", "b", c, d, 2, 4, 5, (a: 1)

// @debug from(('a', 'b', c, d, 2, 4, 5, (a: 1)), 4); // d, 2, 4, 5, (a: 1)
// @debug from(('a', 'b', c, d, 2, 4, 5, (a: 1)), 7); // 5, (a: 1)

// negative index
// @debug from((('a', 'b', 'c'), ), -3); // null, null, ("a", "b", "c"), ("a", "b", "c")

Parameters

$list

The list from which the elements are picked.

$from

A number-type element index of $list.

Return

The return value is the list of elements from index $from to the last index of $list.

Examples

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

// Examples.
@debug list.from((('a', 'b', 'c'),), 1); // (('a', 'b', 'c'),)

@debug list.from((('a', 'b', 'c'), 'a', 'b', c, d, 2, 4, 5, (a: 1)), 0); // ("a", "b", "c"), "a", "b", c, d, 2, 4, 5, (a: 1)
@debug list.from((('a', 'b', 'c'), 'a', 'b', c, d, 2, 4, 5, (a: 1)), -1); // (a: 1), ("a", "b", "c"), "a", "b", c, d, 2, 4, 5, (a: 1)
@debug list.from((('a', 'b', 'c'), 'a', 'b', c, d, 2, 4, 5, (a: 1)), 1); // ("a", "b", "c"), "a", "b", c, d, 2, 4, 5, (a: 1)

@debug list.from(('a', 'b', c, d, 2, 4, 5, (a: 1)), 4); // d, 2, 4, 5, (a: 1)
@debug list.from(('a', 'b', c, d, 2, 4, 5, (a: 1)), 7); // 5, (a: 1)

// negative index
@debug list.from((('a', 'b', 'c'), ), -3); // null, null, ("a", "b", "c"), ("a", "b", "c")

Last updated

Was this helpful?