Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

braveclojure/do-things #2

Open
dianrob opened this issue May 22, 2021 · 0 comments
Open

braveclojure/do-things #2

dianrob opened this issue May 22, 2021 · 0 comments

Comments

@dianrob
Copy link

dianrob commented May 22, 2021

Hi,

I don't know whether here is the correct place to ask my question, so forgive me if i break some code of conduct, please.

Also I enjoyed reading the free(!) version of your book very much so far. Thank you very much for this wonderful resource.

When encountering "reduce" I am lost and can't wrap my head around it.

(defn my-reduce
  ([f initial coll]
   (loop [result initial
          remaining coll]
     (if (empty? remaining)
       result
       (recur (f result (first remaining)) (rest remaining)))))
  ([f [head & tail]]
   (my-reduce f head tail)))

this part here is the beginning of the end of my understanding. Is there additional resources somewhere to somehow grasp the idea? Or should I leave it be, since it is so early in the book? Thank you very much for any response!

EDIT:
Is this part

  ([f initial coll]
   (loop [result initial
          remaining coll]
     (if (empty? remaining)
       result
       (recur (f result (first remaining)) (rest remaining)))))

the argument to my-reduce?

Because up until now we only had arguments in "[]" following a function name. Here the part where i expected an open square bracket indeed starst with a "(".

EDIT II:

I should have read the preceding part more thoroughly. Function overloading ist the answer. Sorry for the fuzz.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant