Fork me on GitHub
#code-reviews
<
2017-06-18
>
Drew Verlee23:06:06

anyone see any problems with my implementation of comp?

(defn my-comp 
  ([] identity)
  ([f] f)
  ([f g] #(f (g %)))
  ([f g & fs]
   (reduce
    (fn [cf func]
      (fn [& args] (cf (apply func args))))
    (my-comp f g) fs)))

noisesmith23:06:06

isn't it guaranteed that only the last function in the chain could possible get more than one arg?

noisesmith23:06:45

I guess you don't need to account for that though

Drew Verlee23:06:31

are you saying that the offical version guarantees that only the last fn can get multiple args?

Drew Verlee23:06:14

This is probably the most meta thing i have ever written in my life, its giving me a headache 🙂

noisesmith23:06:49

the spec for comp itself guarantees this

noisesmith23:06:06

if you do (comp f g h) only h can have more than one arg

Drew Verlee23:06:59

ah, I think thats what was bothering me about the difference between what i wrote and the official version. I was trying to understand how that version accounted for other functions in the chain handling more then one arg.