Class def.Query
Constructor Attributes | Constructor Name and Description |
---|---|
The Query class represents a lazy, one-time enumeration of an item sequence.
|
Method Attributes | Method Name and Description |
---|---|
all(pred, ctx)
Gets a value that indicates if all of the items satisfy a specified predicate.
|
|
any(pred, ctx)
Gets a value that indicates if there is at least one item satisfying a specified predicate.
|
|
array(to)
Converts the query to an array.
|
|
count()
Consumes the query and obtains the number of items.
|
|
distinct(key, ctx)
Obtains a new query with only distinct items.
|
|
each(fun, ctx)
Calls a given function for each item of the query.
|
|
first(pred, ctx, dv)
Returns the first item that satisfies a specified predicate.
|
|
last(pred, ctx, dv)
Returns the last item that satisfies a specified predicate.
|
|
select(fun, ctx)
Transforms the items of a query into other items.
|
|
selectMany(fun, ctx)
Transforms each item of a query into a list of items and flattens the overall result.
|
|
where(pred, ctx)
Obtains a new query with certain items filtered out.
|
Method Detail
{boolean}
all(pred, ctx)
Gets a value that indicates if all of the items satisfy a specified predicate.
- Arguments:
- {function} pred
- A predicate to apply to every item. The function is called with two arguments: the item and the enumeration index at which it occurs. The function returns a truthy value to include the item.
- {any} ctx Optional
- The context object on which to call pred.
- Returns:
- {boolean} true if all of the items satisfy the predicate; false, otherwise.
{boolean}
any(pred, ctx)
Gets a value that indicates if there is at least one item satisfying a specified predicate.
If no predicate is specified, returns true if there is at least one item.
- Arguments:
- {function} pred Optional
- A predicate to apply to every item. The function is called with two arguments: the item and the enumeration index at which it occurs. The function returns a truthy value to include the item.
- {any} ctx Optional
- The context object on which to call pred.
- Returns:
- {boolean} true if there is at least one item satisfying a predicate; false, otherwise.
{Array}
array(to)
Converts the query to an array.
- Arguments:
- {Array} to Optional
- An array to add the items to. One is created and returned when unspecified.
- Returns:
- {Array} The array.
{number}
count()
Consumes the query and obtains the number of items.
- Returns:
- {number} The number of items.
{!def.Query}
distinct(key, ctx)
Obtains a new query with only distinct items.
- Arguments:
- {function} key
- A function that determines the key of each item. The function is called with two arguments: the item and the enumeration index at which it occurs. The function returns the key of the given item. When unspecified, the key is the result of calling toString on an item. Items with nully keys are ignored.
- {any} ctx Optional
- The context object on which to call pred.
- Returns:
- {!def.Query} A query of distinct items.
{boolean}
each(fun, ctx)
Calls a given function for each item of the query.
- Arguments:
- {function} fun
- - The function to call on each item. The function is called with two arguments: the item and the enumeration index at which it occurs. The function can return the exact value false to stop the iteration.
- {object} ctx Optional
- - The JavaScript this object on which to call fun.
- Returns:
- {boolean} true if iteration reached the end of the query; false otherwise.
{any}
first(pred, ctx, dv)
Returns the first item that satisfies a specified predicate.
If no predicate is specified, the first item is returned.
- Arguments:
- {function} pred Optional
- A predicate to apply to every item. The function is called with two arguments: the item and the enumeration index at which it occurs. The function returns a truthy value to include the item.
- {any} ctx Optional
- The context object on which to call pred.
- {any} dv Optional, Default: undefined
- The value returned in case no item exists or satisfies the predicate.
- Returns:
- {any} The first item, if any; the default value otherwise.
{any}
last(pred, ctx, dv)
Returns the last item that satisfies a specified predicate.
If no predicate is specified, the last item is returned.
- Arguments:
- {function} pred Optional
- A predicate to apply to every item. The function is called with two arguments: the item and the enumeration index at which it occurs. The function returns a truthy value to include the item.
- {any} ctx Optional
- The context object on which to call pred.
- {any} dv Optional, Default: undefined
- The value returned in case no item exists or satisfies the predicate.
- Returns:
- {any} The last item, if any; the default value otherwise.
{!def.Query}
select(fun, ctx)
Transforms the items of a query into other items.
- Arguments:
- {function} fun
- - The function to transform each item. The function is called with two arguments: the item and the enumeration index at which it occurs. The function returns the new item.
- {object} ctx Optional
- - The JavaScript this object on which to call fun.
- Returns:
- {!def.Query} A query of the new items.
{!def.Query}
selectMany(fun, ctx)
Transforms each item of a query into a list of items and flattens the overall result.
- Arguments:
- {function} fun
- - The function to transform each item. The function is called with two arguments: the item and the enumeration index at which it occurs. The function returns a new item, a new array of items or a new query of items.
- {object} ctx Optional
- - The JavaScript this object on which to call fun.
- Returns:
- {!def.Query} A flattened query.
{!def.Query}
where(pred, ctx)
Obtains a new query with certain items filtered out.
- Arguments:
- {function} pred
- A predicate to apply to every item. The function is called with two arguments: the item and the enumeration index at which it occurs. The function returns a truthy value to include the item.
- {any} ctx Optional
- The context object on which to call pred.
- Returns:
- {!def.Query} A query of the included items.