filter, filter 1, filter n, filter start, filter start include, filter start n, filter start n include, filter stop, filter stop include
This function extracts a middle part with those elements which fulfill the matching criteria specified in the 2nd parameter.
Unless specified otherwise, empty set is returned in case of no matches. The filter function does not check parameter sets recursively.
Function Name | Behavior |
filter | Returns all elements where matching criteria are met. |
filter 1 | Returns first match only. |
filter n | Limit the number of matches as specified in the 3rd parameter. 0 and negative numbers return empty sets. |
filter start | Returns all remaining elements after and excluding the first match. |
filter start include | Returns all remaining elemetns including and after the first match. |
filter start n | Return maximum specified number of elements after and excluding the first match. |
filter start n include | Return maximum specified number of elements including and after the first match. |
filter stop | Return all elements until before (excluding) the first match. Full set returned if no match identified. |
filter stop include | Return all elements until and including the first match. |
This function may also be called as a procedure in case only the processed followers are needed.
Indirect parameter passing is disabled
Min 2
No. | Type | Description |
---|---|---|
1 input |
parameter set or string | input parameter set If provided as a parameter set: Will be used for counting elements |
2 code |
comparison expression :string |
Right-hand Comparison expression This expression is used to compare every element of the parameter set from left to right. |
Opt. 3 input |
numeral | Count This parameter applies to function names filter n, filter start n and filter start n include.
If provided as a parameter set: Will be used for counting elements |
Opt. 3+ / Opt. 4+ io |
parameter set | follower Other parameter sets in addition to the one provided as the first function parameter can be extracted in the same same way. Add any number of additional parameter set variables. They will be manipulated at the exact same positions as the returned value. |
Type | Description |
---|---|
parameter set | Filtered parameter set |
a[] = {A,1,2,3,4,E,5,2,6 };
print( filter ( a[], >= 3 ), ", " ); // {3,4,5,6}
echo ( filter ( a[], (2,3) ) ); // {2,3,2}
print( filter 1 ( a[], >= 3 ), ", " ); // {3}
echo ( filter n ( a[], >= 3, 3 ) ); // {3,4,5}
print( filter stop ( a[], >= 3 ), ", " ); // { A,1,2}
echo ( filter stop include ( a[], >= 3 ) ); // { A,1,2,3}
print( filter start ( a[], 4 ), ", " ); // {E,5,2,6}
echo ( filter start n ( a[], (4), 3 ) ); // {E,5,2}
// Why is (4) in parentheses? This is a comparison and
// should only be compared with 4, and not with both 4 and 3.
// In the 2nd row, ( a[], (2,3) ) is same as ( a[], 2, 3 ) !
// (4) is same as (=4). (2,3) is same as (=2,3).
print( filter start include ( a[], 4 ), ", " ); // {4,E,5,2,6}
echo ( filter start n include ( a[], (4), 3 ) ); // {4,E,5}
// The follower feature:
b[] = {a,b,c,d,e,f,g,h,i};
c[] = {A,B,C,D,E,F,G,H,I};
filter ( a[], (=2), b[], c[] ); // Attn: (=2) in parentheses
echo( b[], " / ", c[] ); // Outputs {c,h}, {C,H}
b[] = {a,b,c,d,e,f,g,h,i};
c[] = {A,B,C,D,E,F,G,H,I};
filter start n ( a[], (=2), 3, b[], c[] ); // Attn: (=2) in parentheses
echo( b[], " / ", c[] ); // Outputs {d,e,f}, {D,E,F}
{3,4,5,6}, {2,3,2}
{3}, {3,4,5}
{'A',1,2}, {'A',1,2,3}
{'E',5,2,6}, {'E',5,2}
{4,'E',5,2,6}, {4,'E',5}
{'c','h'} / {'C','H'}
{'d','e','f'} / {'D','E','F'}