Next: , Previous: , Up: Higher-Order Functions   [Contents]


1.2 Thrush

function: item() f:thrush (list as item()+)

xmlns:f="http://mikegerwitz.com/hoxsl/apply"

Alias of f:thrushr.

Definition:

<function name="f:thrush"  as="item()">
  <param name="list"  as="item()+" />

  <sequence select="f:thrushr( $list )" />
</function>
function: item() f:thrushr (list as item()+)

xmlns:f="http://mikegerwitz.com/hoxsl/apply"

Given a list of the form (value, f1, f2, ...), return the result ...(f2(f1(value)))

If list consists only of value, simply return value. Any number of functions may be provided in list to form a pipeline; the result of the final application will be returned.

All functions must be unary; partial application should be used to provide beginning arguments. For example, this would yield the value 5:

  <sequence select="f:thrush( 5, f:partial( f:add(), 4 ) )" />

See the apply-gen stylesheet for auto-generating curried functions to simplify the above partial application.

Definition:

<function name="f:thrushr"  as="item()">
  <param name="list"  as="item()+" />

  <sequence select="_f:thrushr-fold( subsequence( $list, 2 ), $list[ 1 ] )" />
</function>
function: item() _f:thrushr-fold (fnref as item()*, result as xs:sequence*)

xmlns:_f="http://mikegerwitz.com/hoxsl/apply/_priv"

Definition:

<function name="_f:thrushr-fold"  as="item()">
  <param name="fnref"  as="item()*" />
  <param name="result" />

  <choose>
    <when test="empty( $fnref )">
      <sequence select="$result" />
    </when>

    <otherwise>
      <!-- FIXME: need abstraction -->
      <variable name="next"  as="item()*"  select="subsequence( $fnref, f:length( $fnref ) + 1 )" />

      <!-- map the next unary function to the previous result, then
           pass that result along for further mapping -->
      <sequence select="_f:thrushr-fold( $next, f:partial( $fnref, $result ) )" />
    </otherwise>
  </choose>
</function>