@function __base-at($collection, $props) {
  $length: length($collection);
  $is-list: type-of($collection) == "list";
  $result: ();

  @each $key in $props {
    @if ($is-list) {
      $key: __parse-float($key);
      $result: append(
        $result,
        if(__is-index($key, $length), nth($collection, $key), null)
      );
    } @else {
      $result: append($result, __get($collection, $key));
    }
  }

  @return $result;
}

@function __at($arguments...) {
  $collection: nth($arguments, 1);
  $length: if($collection, length($collection), 0);

  @if __is-length($length) {
    $collection: __to-iterable($collection);
  }

  @return __base-at($collection, __base-flatten($arguments, false, false, 2));
}

/// Creates a list of elements corresponding to the given keys, or indexes,
/// of `$collection`. Keys may be specified as individual arguments or as lists
/// of keys.
///
/// @access public
/// @group Collection
/// @param {List|Map|string} $collection The collection to iterate over.
/// @param {Number...|String...|List} $props... The property names
///  or indexes of elements to pick, specified individually or in lists.
/// @returns {List} Returns the new list of picked elements.
/// @example scss
/// _at(('a', 'b', 'c'), (1, 3));
/// // => ('a', 'c')
///
/// _at(('fred', 'barney', 'pebbles'), 1, 3);
/// // => ('fred', 'pebbles')

@function _at($args...) {
  @return call(get-function("__at"), $args...);
}
