clojure-dev

Issues: https://clojure.atlassian.net/browse/CLJ | Guide: https://insideclojure.org/2015/05/01/contributing-clojure/
slipset 2020-06-21T18:26:48.322100Z

@seancorfield mentioned the other day that the doc-string for completing is incorrect: "Takes a reducing function f of 2 args and returns a fn suitable for transduce by adding an arity-1 signature that calls cf (default - identity) on the result argument."

slipset 2020-06-21T18:27:40.323100Z

The incorrectness lies in that the function returned by completing can invoke f as a zero-arity fn. Is this worth a issue/patch?

slipset 2020-06-21T18:28:58.323400Z

user> (def f (completing (fn needs-completness [x y] 'yay)))
;; => #'user/f
user> (f)
Execution error (ArityException) at user/eval19641550 (form-init1830575926447082095.clj:2408).
Wrong number of args (0) passed to: user/needs-completness--19641548
user> 

dpsutton 2020-06-21T18:31:17.323800Z

If coll contains no
  items, f must accept no arguments as well, and reduce returns the
  result of calling f with no arguments.
from the docstring of reduce

dpsutton 2020-06-21T18:31:47.324200Z

specifying what a "reducing function" is rather than just a function of two args

slipset 2020-06-21T18:37:12.325600Z

Jepp. So technically not wrong. But then why specify that it's a two args reducing fn, since that's also covered in the docstring of reduce?

seancorfield 2020-06-21T19:53:06.331300Z

Simply removing "of 2 args" would remove the confusion. I wonder if it's worth adding a similar function that takes a function of 2 args and a value, and returns a reducing function that returns that value for the 0-arity call?

(defn reducing
  "Takes a function f of 2 args and a value and returns a reducing
  function that returns the value if called with no arguments or
  calls f if called with two arguments."
  [f v]
  (fn
    ([] v)
    ([x y] (f x y))))
Then you can have (reducing max Long/MIN_VALUE) and completing would compose with that.

slipset 2020-06-21T20:04:44.331900Z

Isn’t that reducers/monoid?

seancorfield 2020-06-21T20:11:00.333500Z

That takes two functions, so it isn't as easy to use, and it's not in clojure.core like completing so it's harder to "discover", and its name doesn't tie in to reducing functions (in the same way that completing ties into how transducers work).