
@function __unzip-iteratee($group, $args...) {
  $length: __this('length');

  @if __is-list-like($group) {
    $_: __this('length', max(length($group), $length));

    @return true;
  }

  @return false;
}

@function __unzip($list) {
  @if __is-falsey($list) {
    @return ();
  }
  
  $list: __to-list($list);

  $index: 1;
  $length: 0;

  $_: __scope(('length': 0));
  $scoped-iteratee: __bind('__unzip-iteratee');
  $list: __list-filter($list, $scoped-iteratee);
  $length: __this('length');
  $_: __scope(false);

  $result: ();

  @while $index <= $length {
    $result: append($result, __list-map($list, __base-property($index)));

    $index: $index + 1;
  }

  @return $result;

    // $index: 1;
    // $length: if($list,
    //   if(length($list) > 0,
    //     __list-max(__list-map($list, '__get-length')),
    //     0),
    //   0);
    // $result: ();

    // @while $index <= $length {
    //     $result: append($result, __list-map($list, __base-property($index)));

    //     $index: $index + 1;
    // }

    // @return $result;
}


/// This method is like `_zip` except that it accepts a list of grouped
/// elements and creates a list regrouping the elements to their pre-`_zip`
/// configuration.
///
///
/// @access public
/// @group List
/// @param {List} $list The list of grouped elements to process.
/// @returns {List} Returns the new list of regrouped elements.
/// @example scss
/// 
/// $zipped: _zip(('fred', 'barney'), (30, 40), (true, false));
/// // => (('fred', 30, true), ('barney', 40, false))
/// 
/// $unzipped: _unzip($zipped);
/// // => (('fred', 'barney'), (30, 40), (true, false))

@function _unzip($args...) {
    @return call(get-function('__unzip'), $args...);
}
