meyfa/group-items

View on GitHub
src/collectors/as-arrays.ts

Summary

Maintainability
A
0 mins
Test Coverage
A
100%
import { Grouping } from '../types.js'

export type ArraysCollection<V> = V[][]

/**
 * Convert the grouping to an array of arrays.
 *
 * @returns The resulting array.
 */
export type ArraysCollector<V> = () => ArraysCollection<V>

/**
 * Create an ArraysCollector for the given grouping.
 *
 * @param groups The grouping.
 * @returns The created collector.
 */
export function asArraysFactory<K, V> (groups: Grouping<K, V>): ArraysCollector<V> {
  return () => {
    return groups.map((g) => g.items)
  }
}