
/* ASSERT */

// Values in a map are in ascending order

@mixin assert-ascending ( $obj, $error: 'Values must be defined in ascending order' ) {

  $previous: null;
  $type: type-of( $obj );

  @if $type == 'list' {

    @for $i from 1 through length( $obj ) {

      $value: nth( $obj, $i );

      @if $previous != null and $previous >= $value {

        @error $error;

      }

      $previous: $value;

    }

  } @else if $type == 'map' {

    @each $key, $value in $obj {

      @if $previous != null and $previous >= $value {

        @error $error;

      }

      $previous: $value;

    }

  } @else {

    @warn '`#{$type}` is not a supported $obj type for `assert-ascending`';

  }

}

// Values in a map are in descending order

@mixin assert-descending ( $map, $error: 'Values must be defined in descending order' ) {

  $previous: null;
  $type: type-of( $obj );

  @if $type == 'list' {

    @for $i from 1 through length( $obj ) {

      $value: nth( $obj, $i );

      @if $previous != null and $previous <= $value {

        @error $error;

      }

      $previous: $value;

    }

  } @else if $type == 'map' {

    @each $key, $value in $obj {

      @if $previous != null and $previous <= $value {

        @error $error;

      }

      $previous: $value;

    }

  } @else {

    @warn '`#{$type}` is not a supported $obj type for `assert-ascending`';

  }

}
