@function first($list) {
  @return nth($list, 1);
}

@function last($list) {
  @return nth($list, length($list));
}

@function next($list, $value) {
  @return nth($list, index($list, $value) + 1);
}

@function prev($list, $value) {
  @return nth($list, index($list, $value) - 1);
}

@function map_get_default($map, $key) {
  @if map_has_key($map, $key) {
    @return map_get($map, $key);
  } @else if map_has_key($map, default) {
    @return map_get($map, default);
  } @else {
    @error "map key " + $key + " does not exists";
  }
}

@function get_breakpoint($breakpoint) {
  @if map_has_key($lrj-media-breakpoints, $breakpoint) {
    @return map_get($lrj-media-breakpoints, $breakpoint)
  } @else {
    @error "breakpoint " + $breakpoint + " is not set";
  }
}

@function breakpoint_name($breakpoint) {
  @if ($breakpoint == default) {
    @return "";
  } @else {
    @return #{"-" + $breakpoint}
  }
}

@function remove($list, $value, $recursive: false) {
  $result: ();
  @for $i from 1 through length($list) {
    @if type-of(nth($list, $i)) == list and $recursive {
      $result: append($result, remove(nth($list, $i), $value, $recursive));
    } @else if nth($list, $i) != $value {
      $result: append($result, nth($list, $i));
    }
  }
  @return $result;
}

@function get($variable, $breakpoint: default) {
  @return map_get($variable, $breakpoint);
}

@function str_replace($string, $search, $replace: '') {
  $index: str-index($string, $search);

  @if $index {
    @return str-slice($string, 1, $index - 1) + $replace + str-replace(str-slice($string, $index + str-length($search)), $search, $replace);
  }

  @return $string;
}