get-from-list()

@function get-from-list($list, $keys...) {
  $map: ();
  @if list.length($list) > 1 {
    $index: 1;

    @each $value in $list {
      @if type-of($value) != 'map' {
        $key: list.nth($keys, $index);
        @if type-of($key) == 'map' {
          @each $k, $type in $key {
            @if typeof($value) == $type {
              // @warn '#{$k} #{$type} #{$value}';
              $map: map.set($map, $k, $value);
            }
          }
        } @else {
          $map: map.set($map, $key, $value);
        }
        $index: $index + 1;
      }
    }

    @each $value in $list {
      @if type-of($value) == 'map' {
        @each $key in $keys {
          @if type-of($key) != 'map' {
            @if map.has-key($value, $key) {
              $map: map.set($map, $key, map.get($value, $key));
            }
          } @else {
            @each $k, $type in $key {
              @if typeof(map.get($value, $k)) == $type {
                $map: map.set($map, $k, map.get($value, $k));
              }
            }              
          }
        }
      }
    }
  } @else {
    $map: map.set($map, list.nth($keys, 1), $list);
  }
  @return $map;
}

Last updated