function filter(
	items = new List(),
	query = '',
	{ nameAttr = 'name', onMatch = noop } = {},
	currentPosition = 'root',
) {
	if (query) {
		return items.reduce((accumulator, item) => {
			if (isLeafElement(item)) {
				return matchOnLeaf(item, currentPosition, query, nameAttr, onMatch, accumulator);
			}
			const currentElementName = item.get(nameAttr, '');
			const result = filter(
				item.get('children'),
				query,
				{ nameAttr },
				`${currentPosition} > ${currentElementName}`,
			);
			return accumulator.concat(result);
		}, new List());
	}
	return items;
}
/**
 * apply query only on leaf elements, return them on a single list,
 * not taking into account the deepth of matched elements.
 * @return item in items found with the id
 * @param {Object} options {query, items, idAttr }
 */
apply query only on leaf elements, return them on a single list,
not taking into account the deepth of matched elements.
@return item in items found with the id
@param {Object} options {query, items, idAttr }
apply query only on leaf elements return them on a single list not taking into account the deepth of matched elements . @return item in items found with the id @param { Object } options { query items idAttr }
function filter(
	items = new List(),
	query = '',
	{ nameAttr = 'name', onMatch = noop } = {},
	currentPosition = 'root',
) {
	if (query) {
		return items.reduce((accumulator, item) => {
			if (isLeafElement(item)) {
				return matchOnLeaf(item, currentPosition, query, nameAttr, onMatch, accumulator);
			}
			const currentElementName = item.get(nameAttr, '');
			const result = filter(
				item.get('children'),
				query,
				{ nameAttr },
				`${currentPosition} > ${currentElementName}`,
			);
			return accumulator.concat(result);
		}, new List());
	}
	return items;
}
function filter ( items = new List ( ) , query = '' , { nameAttr = 'name' , onMatch = noop } = { } , currentPosition = 'root' , ) { if ( query ) { return items . reduce ( ( accumulator , item ) => { if ( isLeafElement ( item ) ) { return matchOnLeaf ( item , currentPosition , query , nameAttr , onMatch , accumulator ) ; } const currentElementName = item . get ( nameAttr , '' ) ; const result = filter ( item . get ( 'children' ) , query , { nameAttr } , ` ${ currentPosition } ${ currentElementName } ` , ) ; return accumulator . concat ( result ) ; } , new List ( ) ) ; } return items ; }
apply query only on leaf elements, return them on a single list,
 not taking into account the deepth of matched elements.
apply query only on leaf elements return them on a single list not taking into account the deepth of matched elements .