Skip to content

functional-programming chapter; improve examples and explain iterate #8

@timothypratley

Description

@timothypratley

your exercises for functional-programming chapter rely heavily on iterate, but that's not brought up in the chapter. Exercise for the author: how do you solve those problems without iterate? (Doable, in theory.) More seriously, it might be better to defer those exercises in favor of something more related to map, reduce, and/or filter.

Also, maybe have an exercise to just rewrite an existing super nested expression using a threading macro, since the topic was covered? Ex, when already given:

(defn count-i-before-e
  [s]
  (count (filter #(= % [\i \e]) (partition 2 1 (seq s)))))

Try: (count-i-before-e "sieve") and (count-i-before-e "seize") Now rewrite using thread-last macro (->>):

(defn count-i-before-e
  [s]
  (->> s
       seq
       (partition 2 1)
       (filter #(= % [\i \e]))
       count))

I think some work can go into exercises for map/reduce/filter to replace the ones using iterate, what do you think? I would need some time to think on what to come up with ideas for that.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions