@@ -130,35 +130,45 @@ export class Result extends Array<any> {
130130    } 
131131
132132    /** 
133-      *  Returns the Result as a normal Array. 
133+      *  Returns the Result as a normal Array. If %%deep%%, any children 
134+      *  which are Result objects are also converted to a normal Array. 
134135     * 
135136     *  This will throw if there are any outstanding deferred 
136137     *  errors. 
137138     */ 
138-     toArray ( ) : Array < any >  { 
139+     toArray ( deep ?:  boolean ) : Array < any >  { 
139140        const  result : Array < any >  =  [  ] ; 
140141        this . forEach ( ( item ,  index )  =>  { 
141142            if  ( item  instanceof  Error )  {  throwError ( `index ${  index  }  ,  item ) ;  } 
143+             if  ( deep  &&  item  instanceof  Result )  { 
144+                 item  =  item . toArray ( deep ) ; 
145+             } 
142146            result . push ( item ) ; 
143147        } ) ; 
144148        return  result ; 
145149    } 
146150
147151    /** 
148-      *  Returns the Result as an Object with each name-value pair. 
152+      *  Returns the Result as an Object with each name-value pair. If 
153+      *  %%deep%%, any children which are Result objects are also 
154+      *  converted to an Object. 
149155     * 
150156     *  This will throw if any value is unnamed, or if there are 
151157     *  any outstanding deferred errors. 
152158     */ 
153-     toObject ( ) : Record < string ,  any >  { 
159+     toObject ( deep ?:  boolean ) : Record < string ,  any >  { 
154160        return  this . #names. reduce ( ( accum ,  name ,  index )  =>  { 
155161            assert ( name  !=  null ,  "value at index ${ index } unnamed" ,  "UNSUPPORTED_OPERATION" ,  { 
156162                operation : "toObject()" 
157163            } ) ; 
158164
159165            // Add values for names that don't conflict 
160166            if  ( ! ( name  in  accum ) )  { 
161-                 accum [ name ]  =  this . getValue ( name ) ; 
167+                 let  child  =  this . getValue ( name ) ; 
168+                 if  ( deep  &&  child  instanceof  Result )  { 
169+                     child  =  child . toObject ( deep ) ; 
170+                 } 
171+                 accum [ name ]  =  child ; 
162172            } 
163173
164174            return  accum ; 
0 commit comments