Skip to content
This repository
Browse code

limit unary hypers to declared shape or flat

Also add .duckmap and .deepmap to give the less huffmanly desirable
semantics.
  • Loading branch information...
commit b3233b4ccfe2a65ceae78df44d162de8cb0699a7 1 parent d46a8ab
Larry Wall authored September 15, 2012
17  S03-operators.pod
Source Rendered
@@ -14,8 +14,8 @@ Synopsis 3: Perl 6 Operators
14 14
 
15 15
     Created: 8 Mar 2004
16 16
 
17  
-    Last Modified: 11 August 2012
18  
-    Version: 257
  17
+    Last Modified: 15 Sep 2012
  18
+    Version: 258
19 19
 
20 20
 =head1 Overview
21 21
 
@@ -4121,9 +4121,16 @@ require parens.)
4121 4121
 A unary hyper operator (either prefix or postfix) has only one
4122 4122
 hyper marker, located on its argument side, while an infix operator
4123 4123
 always has one on each side to indicate there are two arguments.
4124  
-Unary operators always produce a list or array of exactly the same
4125  
-shape as their single argument (at least down to the level that the operator
4126  
-may be applied).  When infix operators are presented with
  4124
+
  4125
+Unary hyper operators always produce a hash or array of exactly the
  4126
+same I<declared> shape as the single argument.  If the item is not
  4127
+declared with a shape, only the top dimension is mapped, equivalent
  4128
+to a normal C<.map> method.  (To map deeper dimensions than provided
  4129
+for by hypers, use the either C<.duckmap> or C<.deepmap> method,
  4130
+depending on whether you want to give the item mapping or the
  4131
+substructure first shot at each node.)
  4132
+
  4133
+When infix operators are presented with
4127 4134
 two lists or arrays of identical shape, a result of that same shape is
4128 4135
 produced.  Otherwise the result depends on how you write the hyper
4129 4136
 markers.
37  S32-setting-library/Containers.pod
Source Rendered
@@ -19,8 +19,8 @@ DRAFT: Synopsis 32: Setting Library - Containers.pod
19 19
 
20 20
     Created: 19 Feb 2009 extracted from S29-functions.pod
21 21
 
22  
-    Last Modified: 27 Aug 2012
23  
-    Version: 31
  22
+    Last Modified: 15 Sept 2012
  23
+    Version: 32
24 24
 
25 25
 The document is a draft.
26 26
 
@@ -325,6 +325,39 @@ an argument will iterate or terminate the C<map> itself, not some
325 325
 loop surrounding the statement containing the C<map>.  Use a label
326 326
 if you mean the other thing.
327 327
 
  328
+=item duckmap
  329
+
  330
+ multi method duckmap ( @values: Code *&expression --> List of Parcel )
  331
+ multi duckmap ( Code $expression, *@values --> List of Parcel )
  332
+
  333
+Like C<map>, C<duckmap> evaluates the expression for each of the
  334
+values that is passed in.  Unlike C<map>, if the evaluation produces
  335
+an undefined value, a failover looks to see if this element actually
  336
+contains subelements, and if so, reapplies the duckmap recursively,
  337
+returning the structured result for that element, so that the
  338
+structure of the original is (largely) retained in the result.
  339
+Unlike C<deepmap>, it does not guarantee the same structure, since
  340
+the mapping expression takes precedence over structure in cases where
  341
+either would succeed.
  342
+
  343
+Because C<duckmap> is defined as a recursive implicit loop, loop
  344
+controls apply only to the current level of the tree.
  345
+
  346
+=item deepmap
  347
+
  348
+ multi method deepmap ( @values: Code *&expression --> List of Parcel )
  349
+ multi deepmap ( Code $expression, *@values --> List of Parcel )
  350
+
  351
+Like C<map> and C<duckmap>, C<deepmap> evaluates the expression for
  352
+each of the values you give it.  Unlike C<map> and C<duckmap>, an
  353
+element is considered a value only if it does not do the C<Iterable>
  354
+role.  If the element is iterable, the algorithm recurses to produce
  355
+an identical structure to its input.  Elements that are not iterable
  356
+are considered leaf values and mapped through the supplied expression.
  357
+
  358
+Because C<deepmap> is defined as a recursive implicit loop, loop
  359
+controls apply only to the current level of the tree.
  360
+
328 361
 =item reduce
329 362
 
330 363
  multi method reduce ( @values: Code *&expression --> Item )

0 notes on commit b3233b4

Please sign in to comment.
Something went wrong with that request. Please try again.