import { GroupBy } from './query/groupby' ; /**
 * An ordered tree structure for storing query results.
 */ export interface ResultTree < T > { name : string ; path : string ; items : ( ResultTree < T > | T ) [ ] ; groupBy ? : GroupBy ; orderGroupBy ? : string | string [ ] ; } export function isResultTree < T > ( item ) { return ( < ResultTree < T > > item ) . items !== undefined ; } export function getTopResultTreeItem < T > ( specQuery ) { let topItem = specQuery . items [ 0 ] ; while ( topItem && isResultTree ( topItem ) ) { topItem = topItem . items [ 0 ] ; } return < T > topItem ; } export function mapLeaves < T , U > ( group , f ) { return { ... group , items : group . items . map ( ( item ) => ( isResultTree ( item ) ? mapLeaves ( item , f ) : f ( item ) ) ) , } ; }