Browse files

limit unary hypers to declared shape or flat

Also add .duckmap and .deepmap to give the less huffmanly desirable
  • Loading branch information...
TimToady committed Sep 16, 2012
1 parent d46a8ab commit b3233b4ccfe2a65ceae78df44d162de8cb0699a7
Showing with 47 additions and 7 deletions.
  1. +12 −5 S03-operators.pod
  2. +35 −2 S32-setting-library/Containers.pod
@@ -14,8 +14,8 @@ Synopsis 3: Perl 6 Operators
Created: 8 Mar 2004
- Last Modified: 11 August 2012
- Version: 257
+ Last Modified: 15 Sep 2012
+ Version: 258
=head1 Overview
@@ -4121,9 +4121,16 @@ require parens.)
A unary hyper operator (either prefix or postfix) has only one
hyper marker, located on its argument side, while an infix operator
always has one on each side to indicate there are two arguments.
-Unary operators always produce a list or array of exactly the same
-shape as their single argument (at least down to the level that the operator
-may be applied). When infix operators are presented with
+Unary hyper operators always produce a hash or array of exactly the
+same I<declared> shape as the single argument. If the item is not
+declared with a shape, only the top dimension is mapped, equivalent
+to a normal C<.map> method. (To map deeper dimensions than provided
+for by hypers, use the either C<.duckmap> or C<.deepmap> method,
+depending on whether you want to give the item mapping or the
+substructure first shot at each node.)
+When infix operators are presented with
two lists or arrays of identical shape, a result of that same shape is
produced. Otherwise the result depends on how you write the hyper
@@ -19,8 +19,8 @@ DRAFT: Synopsis 32: Setting Library - Containers.pod
Created: 19 Feb 2009 extracted from S29-functions.pod
- Last Modified: 27 Aug 2012
- Version: 31
+ Last Modified: 15 Sept 2012
+ Version: 32
The document is a draft.
@@ -325,6 +325,39 @@ an argument will iterate or terminate the C<map> itself, not some
loop surrounding the statement containing the C<map>. Use a label
if you mean the other thing.
+=item duckmap
+ multi method duckmap ( @values: Code *&expression --> List of Parcel )
+ multi duckmap ( Code $expression, *@values --> List of Parcel )
+Like C<map>, C<duckmap> evaluates the expression for each of the
+values that is passed in. Unlike C<map>, if the evaluation produces
+an undefined value, a failover looks to see if this element actually
+contains subelements, and if so, reapplies the duckmap recursively,
+returning the structured result for that element, so that the
+structure of the original is (largely) retained in the result.
+Unlike C<deepmap>, it does not guarantee the same structure, since
+the mapping expression takes precedence over structure in cases where
+either would succeed.
+Because C<duckmap> is defined as a recursive implicit loop, loop
+controls apply only to the current level of the tree.
+=item deepmap
+ multi method deepmap ( @values: Code *&expression --> List of Parcel )
+ multi deepmap ( Code $expression, *@values --> List of Parcel )
+Like C<map> and C<duckmap>, C<deepmap> evaluates the expression for
+each of the values you give it. Unlike C<map> and C<duckmap>, an
+element is considered a value only if it does not do the C<Iterable>
+role. If the element is iterable, the algorithm recurses to produce
+an identical structure to its input. Elements that are not iterable
+are considered leaf values and mapped through the supplied expression.
+Because C<deepmap> is defined as a recursive implicit loop, loop
+controls apply only to the current level of the tree.
=item reduce
multi method reduce ( @values: Code *&expression --> Item )

0 comments on commit b3233b4

Please sign in to comment.