// Sass.
@use 'sass:list';
// Status: DONE
// The `list.nth()` function returns the element of `$list` at index `$n` and/or with elements of given indexes `$nts...`.
// Function modify original by adding `$nts...` arbitrary parameter at the end.
// @param `$list` A list from which the element of index `$n` and/or multiple indexes `$nts` are retrieved.
// @param `$n` The required index of `$list`.
// @arbitrary `$nts...` Optional multiple indexes of `$list`.
// @return The return value is a retrieved element or list of retrieved elements.
@function nth($list, $n, $nts...) {
$result: ();
@each $n in list.join($n, $nts, comma) {
@if $n and $n != 0 {
$result: list.append(
$result,
if(list.length($list) >= if($n < 0, calc($n * -1), $n), list.nth($list, $n), null),
list.separator($list)
);
}
}
@return if(list.length($nts) > 0, $result, list.nth($result, 1));
}
// Examples.
// single `$n`
// @debug nth(('a', 'b', 'c', 'd', 'e', 'f'), 4); // d
// multiple `$nts...`
// @debug nth(('a', 'b', 'c', 'd', 'e', 'f'), 4, 3, 4); // "d", "c", "d"
// null or false
// @debug nth(('a', 'b', 'c', 'd', 'e', 'f'), 10); // null
// @debug nth(('a', 'b', 'c', 'd', 'e', 'f'), 10) or false; // false
// @debug nth(('a', 'b', 'c', 'd', 'e', 'f'), -10); // null
// @debug nth(('a', 'b', 'c', 'd', 'e', 'f'), -10) or false; // false