@function reverse($list, $recursive: false) {
  $result: ();

  @for $i from length($list)*-1 through -1 {
    @if type-of(nth($list, abs($i))) == list and $recursive {
      $result: append($result, reverse(nth($list, abs($i)), $recursive));
    }

    @else {
      $result: append($result, nth($list, abs($i)));
    }
  }

  @return $result;
}