_cons-until-empty_: Add @only@

* vector/list.xml (_cons-until-empty_): Add @only@, which has the opposite
    behavior to @glance@.
  (_merge-until-empty_): Proxy @only@.
master
Mike Gerwitz 2018-01-29 13:19:15 -05:00
parent 34f7c6bef1
commit 46c230febb
1 changed files with 29 additions and 7 deletions

View File

@ -26,6 +26,7 @@
<import package="../base" />
<import package="../numeric/common" export="true" />
<import package="../when" export="true" />
@ -49,6 +50,7 @@
<param name="@base@" desc="Base set to return (otherwise an empty set)" />
<param name="@glance@" desc="Glance at (but do nothing with) this value; recurse without action" />
<param name="@only@" desc="Process only this value; otherwise recurse without action" />
<!-- intended for use by merge-until-empty to reduce duplicate code; not to
be set via direct template applications -->
@ -102,17 +104,35 @@
</c:values>
<!-- this case statement will be optimized away if we have no
@glance@ value -->
@glance@ or @only@ value -->
<c:cases>
<!-- if we have a glancing value, then immediately recurse
without processing if we have a match -->
<if name="@glance@">
<c:case>
<c:when name="@car@">
<c:eq>
<c:value-of name="@glance@" />
</c:eq>
</c:when>
<t:when-eq name="@car@" value="@glance@" />
<c:recurse>
<c:arg name="@set@">
<c:value-of name="@cdr@" />
</c:arg>
<if name="@index@">
<c:arg name="@index@">
<t:inc>
<c:value-of name="@index@" />
</t:inc>
</c:arg>
</if>
</c:recurse>
</c:case>
</if>
<!-- if we should only recurse when a value matches, ignore
non-match -->
<if name="@only@">
<c:case>
<t:when-ne name="@car@" value="@only@" />
<c:recurse>
<c:arg name="@set@">
@ -206,9 +226,11 @@
</param>
<param name="@glance@" desc="Glance at (but do nothing with) this value; recurse without action" />
<param name="@only@" desc="Process only this value; otherwise recurse without action" />
<!-- to reduce duplicate template code, we simply set a merge flag on cons-until-empty -->
<t:cons-until-empty set="@set@" car="@car@" cdr="@cdr@" glance="@glance@" merge="true">
<t:cons-until-empty set="@set@" car="@car@" cdr="@cdr@"
glance="@glance@" only="@only@" merge="true">
<param-copy name="@values@" />
</t:cons-until-empty>
</template>