File tree Expand file tree Collapse file tree 2 files changed +21
-15
lines changed Expand file tree Collapse file tree 2 files changed +21
-15
lines changed Original file line number Diff line number Diff line change 24352435       ([x y] (f  (g  x y)))
24362436       ([x y z] (f  (g  x y z)))
24372437       ([x y z & args] (f  (apply  g x y z args)))))
2438-   ([f g h] 
2439-      (fn  
2440-        ([] (f  (g  (h ))))
2441-        ([x] (f  (g  (h  x))))
2442-        ([x y] (f  (g  (h  x y))))
2443-        ([x y z] (f  (g  (h  x y z))))
2444-        ([x y z & args] (f  (g  (apply  h x y z args))))))
2445-   ([f1 f2 f3 & fs]
2446-     (let  [fs (reverse  (list*  f1 f2 f3 fs))]
2447-       (fn  [& args]
2448-         (loop  [ret (apply  (first  fs) args) fs (next  fs)]
2449-           (if  fs
2450-             (recur  ((first  fs) ret) (next  fs))
2451-             ret))))))
2438+   ([f g & fs]
2439+      (reduce1  comp (list*  f g fs))))
24522440
24532441(defn  juxt  
24542442  " Takes a set of functions and returns a fn that is the juxtaposition
Original file line number Diff line number Diff line change 1717import  java .util .List ;
1818import  java .util .concurrent .atomic .AtomicBoolean ;
1919
20- public  class  PersistentVector  extends  APersistentVector  implements  IObj , IEditableCollection {
20+ public  class  PersistentVector  extends  APersistentVector  implements  IObj , IEditableCollection ,  IReduce {
2121
2222public  static  class  Node  implements  Serializable  {
2323	transient  public  final  AtomicBoolean  edit ;
@@ -260,6 +260,24 @@ public void remove(){
260260
261261public  Iterator  iterator (){return  rangedIterator (0 ,count ());}
262262
263+ public  Object  reduce (IFn  f ){
264+ 	throw  new  UnsupportedOperationException ();
265+ }
266+ 
267+ public  Object  reduce (IFn  f , Object  init ){
268+     int  step  = 0 ;
269+     for (int  i =0 ;i <cnt ;i +=step ){
270+         Object [] array  = arrayFor (i );
271+         for (int  j  =0 ;j <array .length ;++j ){
272+             init  = f .invoke (init ,array [j ]);
273+             if (RT .isReduced (init ))
274+ 	            return  ((IDeref )init ).deref ();
275+             }
276+         step  = array .length ;
277+     }
278+     return  init ;
279+ }
280+ 
263281public  Object  kvreduce (IFn  f , Object  init ){
264282    int  step  = 0 ;
265283    for (int  i =0 ;i <cnt ;i +=step ){
 
 
   
 
     
   
   
          
    
    
     
    
      
     
     
    You can’t perform that action at this time.
  
 
    
  
    
      
        
     
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments