Water 5-Common Data Types-Generic Object and Collection
method subvector
Return a contiguous subset of vector-keyed objects from an object
Contract
Return typewob
Parameter keyDefault valueType
start0integer
endoptinteger
Water Contract
<method subvector
  start=0=number.integer
  end  =opt=number.integer/>

See also: vector, length, subvectors


This method returns a contiguous subset of vector-keyed objects from a _subject . This method works with any object containing vector-keyed fields. The returned object is of the same class as the _subject .

<thing "one" "two" "three" "four" />.<subvector 1 3 />
<thing "two" "three"/>
Example: Only works with vector-keyed fields
<thing red=10 green=20 blue=30 "one" "two" "three" "four" />.<subvector 1 3 />
<thing "two" "three"/>

a wob
Parameter keyDefault valueType
start0integer


Indicates the starting point of the subvector (zero-relative). If start is greater than the number of vector-keyed fields in the object, this method will throw an error.

The contents of a vector can be subvectored. This example uses only the start field with no end specified.

<v 0 1 2 3 4 5 6 7 8 9 />.<subvector 5 />
<v 5 6 7 8 9/>

a wob
Parameter keyDefault valueType
endoptinteger


Indicates the key position one greater than the last position to be included in the subvector (zero-relative).
If end is larger than the number of vector-keyed fields in the object, the returned value only extends to the last vector-keyed value. For strings each character is treated as a vector-keyed value.

"abcdefgh".<subvector 4 99 />"efgh"

It even works with HTML data:

<div>
 <p>para one</p>
 <p>para two</p>
 <p>para three</p>
</div>.<subvector 0 2 />
<div <p "para one" /> <p "para two" />/>

An end value less than the start value will cause the method to throw an error.


If either start or end is negative, this method will throw an error.

<try if_error="error">
"abcd".<subvector -1 0 />
</try>
"error"