SubsetNew (UnicodeNamedArraylist function): Difference between revisions
m (1 revision) |
m (→See also) |
||
(One intermediate revision by one other user not shown) | |||
Line 14: | Line 14: | ||
<p>For example, <code>LT(this, 91)</code> is the criterion <code>this < 91</code>, where <code>this</code> is an identity function that simply returns the item's value. The items that satisfy this expression populate the <var>UnicodeNamedArraylist</var> that <var>SubsetNew</var> returns. | <p>For example, <code>LT(this, 91)</code> is the criterion <code>this < 91</code>, where <code>this</code> is an identity function that simply returns the item's value. The items that satisfy this expression populate the <var>UnicodeNamedArraylist</var> that <var>SubsetNew</var> returns. | ||
</p> | </p> | ||
<p>The function in the criterion is a method value (a method or class member name literal, or a method variable) for a method that operates on items of the type specified on the <var class="term">uniNal</var> declaration and that returns an intrinsic value. This is described further in [[SelectionCriterion class#Specifying a SelectionCriterion's parameters|"Specifying a SelectionCriterion's parameters"]]. | <p>The function in the criterion is a method value (a method or class member name literal, or a [[Method variables|method variable]]) for a method that operates on items of the type specified on the <var class="term">uniNal</var> declaration and that returns an intrinsic value. This is described further in [[SelectionCriterion class#Specifying a SelectionCriterion's parameters|"Specifying a SelectionCriterion's parameters"]]. | ||
</p></td></tr> | </p></td></tr> | ||
</table> | </table> | ||
==Examples== | ==Examples== | ||
In the following request, a <var>SubsetNew</var> call uses a selection criterion that first applies the intrinsic [[Length (String function)|Length]] function to the collection items: | |||
<p class="code">begin | <p class="code">begin | ||
%k is unicodeNamedArraylist of longstring | %k is unicodeNamedArraylist of longstring | ||
Line 44: | Line 44: | ||
2: §.Jun: Ursa Minor | 2: §.Jun: Ursa Minor | ||
3: §.Nov: Andromeda | 3: §.Nov: Andromeda | ||
</p | </p> | ||
==See also== | ==See also== | ||
<ul> | <ul> | ||
<li><var>[[FindNextItem (UnicodeNamedArraylist function)|FindNextItem]]</var> is similar to <var>SubsetNew</var> except that it returns just the first matching item it encounters. | <li><var>[[FindNextItem (UnicodeNamedArraylist function)|FindNextItem]]</var> is similar to <var>SubsetNew</var> except that it returns just the first matching item it encounters. | ||
<li>The <var>NamedArraylist</var> <var>[[SubsetNew (NamedArraylist function)|SubsetNew]]</var> and <var>FloatNamedArraylist</var> <var>[[SubsetNew (FloatNamedArraylist function)|SubsetNew]]</var> functions also perform the subsetting function — for their respective classes. The examples on those pages may provide for possible additional approaches for <var>SubsetNew</var>. | |||
</ul> | </ul> | ||
{{Template:UnicodeNamedArraylist:SubsetNew footer}} | {{Template:UnicodeNamedArraylist:SubsetNew footer}} |
Latest revision as of 16:39, 3 August 2012
Create UnicodeNamedArraylist of items matching some selection criteria (UnicodeNamedArraylist class)
SubsetNew searches the entire UnicodeNamedArraylist to find and return all items that match a specified criterion. The criterion is supplied by the SelectionCriterion object that is the required SubsetNew parameter. If no item satisfies the criterion, SubsetNew returns an empty UnicodeNamedArraylist.
Syntax
%outUniNal = uniNal:SubsetNew( selectionCriterion)
Syntax terms
%outUniNal | A UnicodeNamedArraylist variable of the same type as the method UnicodeNamedArraylist (uniNal) to contain the items that are located by the search. If outUniNal is not empty, its contents are discarded before it is populated by the items returned from SubsetNew. |
---|---|
uniNal | A UnicodeNamedArraylist object. |
selectionCriterion | A SelectionCriterion object, which is a relational expression that is applied to a uniNal item value to determine whether the value satisfies the expression. The expression consists of a function, an operator, and a User Language intrinsic type (numeric, string, or Unicode) value.
For example, The function in the criterion is a method value (a method or class member name literal, or a method variable) for a method that operates on items of the type specified on the uniNal declaration and that returns an intrinsic value. This is described further in "Specifying a SelectionCriterion's parameters". |
Examples
In the following request, a SubsetNew call uses a selection criterion that first applies the intrinsic Length function to the collection items:
begin %k is unicodeNamedArraylist of longstring %kk is unicodeNamedArraylist of longstring %k = new %k('§Jan':u) = 'Orion' %k('§Apr':u) = 'Leo' %k('§Mar':u) = 'Cancer' %k('§Jun':u) = 'Ursa Minor' %k('§Nov':u) = 'Andromeda' %k('§Dec':u) = 'Aries' %k('§Feb':u) = 'Canis Major' %sel is object selectionCriterion for longstring %n is float %sel = GE(length, 9) %kk = %k:subsetNew(%sel) %kk:print end
The result is:
1: §.Feb: Canis Major 2: §.Jun: Ursa Minor 3: §.Nov: Andromeda
See also
- FindNextItem is similar to SubsetNew except that it returns just the first matching item it encounters.
- The NamedArraylist SubsetNew and FloatNamedArraylist SubsetNew functions also perform the subsetting function — for their respective classes. The examples on those pages may provide for possible additional approaches for SubsetNew.