@function __splice($list, $start, $delete-count: 1, $items...) {
  $length: length($list);
  $result: ();
  $index: 1;

  // @return false;

  @while $index < $start {
    $result: append($result, nth($list, $index));
    $index: $index + 1;
  }

  @each $item in $items {
    $result: append($result, $item);
  }

  $index: $start + $delete-count;

  @while $index <= $length {
    $result: append($result, nth($list, $index));
    $index: $index + 1;
  }

  @return $result;
}

/// Removes items from a `$list` and adds new items in their place.
/// Similar to the native JavaScript [splice() function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/splice).
///
/// @access public
/// @group List
/// @param {List} $list - List to splice.
/// @param {Number} $start - Index to start changing the list.
/// @param {Number} $delete-count [1] - Number of list items to remove.
/// @param {Any...} $items... - Items to add to the lsit.
/// @example scss
/// $margin: 10px 3px 5px 20px;
///
/// $margin: _splice($margin, 2, 2, 15px);
/// // => 10px 15px 20px

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