// =============================================================================
// =ALEKSI - MAP-SELECT
// =============================================================================
////
//// @group aleksi-maps
//// @author [Yoannis Jamar](https://yoannis.com)

@import "aleksi/general/throw";
@import "aleksi/maps/is-map";

// =map-select-keys( $map, $keys )
// -----------------------------------------------------------------------------
/// Reduces a map's by selecting some of its keys only.
///
/// @param {map} $map - The map to reduce.
/// @param {list} $keys - The keys to keep in the resulting map.
///
/// @return {map} - `$map` with only the keys present in `$keys`.
/// @throw Error if `$map` is not a map.
///
/// @example scss
///   $foo: map-select( ('a': 'foo', 'b': 'bar', 'c': 'baz'), 'a' 'c');
///     // => ('a': 'foo', 'c': 'baz')
///
/// @access public
/// @since 0.1.0

@function map-select-keys( $map, $keys )
{
  @if not is-map($map) {
    @return throw-error('map-select():: $map must be a map, was #{inspect($map)}.');
  }

  $res: ();

  @each $key, $value in $map {
    @if index($keys, $key) {
      $res: map-merge($res, ($key: $value));
    }
  }

  @return $res;
}

// =map-select( $map, $keys )
// -----------------------------------------------------------------------------
/// @alias map-select-keys
///
/// @access public
/// @since 0.1.0

@function map-select( $map, $keys )
{
  @return map-select-keys( $map, $keys );
}