Skip to content

Update applying-functions-to.asciidoc #149

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

Merged
merged 8 commits into from
Aug 2, 2013

Conversation

temacube
Copy link
Contributor

@temacube temacube commented Aug 1, 2013

Example definition of map-kv via reduce-kv

Example definition of map-kv via reduce-kv
Added require to alias clojure.string
simplified example string parsing
@qtrfeast
Copy link
Member

qtrfeast commented Aug 2, 2013

Great little example. Could you move the old original reduce-kv above your addition? The only other thing I need is a license assignment and we can merge this.

@temacube
Copy link
Contributor Author

temacube commented Aug 2, 2013

Ok, I've never used github before, so I may need to play around a little. My licensing will be as in free beer, so you are free to modify anything as you see fit. I'll find the way to plug that in.

Likewise I noted (and was trying to get a handle on) the fact that "merge" doesn't do the "bubble-max-key" or "clojure.set/difference" performance hacks. It's probably not germane to a simple example, but could be important for large maps.

As as side note I've also been playing around with "sorted-map-by" which seems to give people trouble on the internet. The "compare-key-index" function is odd b/c it takes two keys not two pairs.

Here's an example snippet demonstrating my understanding. I'll find some where to patch this stuff in.


(defn make-keyword [s n](keyword %28str s n%29))

(defn pairs
([](pairs 0 0))
([i](pairs i i))
([i n](cons [%28make-keyword "s" i) n]
(lazy-seq (pairs (inc i) (inc n))))))

(defn key-index [k](-> k str %28subs 2%29 Long.))

(defn compare-key-index [k1 k2](compare %28key-index k1%29 %28key-index k2%29))

(defn sorted-pairs [& mps](reduce #%28into %1 %2%29 %28sorted-map-by compare-key-index%29 mps))

(sorted-pairs (take 2 (pairs)) (take 2 (pairs 1 2)))

On Aug 1, 2013, at 6:03 PM, Ryan Neufeld notifications@github.com wrote:

Great little example. Could you move the old original reduce-kv above your addition? The only other thing I need is a license assignment and we can merge this.


Reply to this email directly or view it on GitHub.

@qtrfeast
Copy link
Member

qtrfeast commented Aug 2, 2013

Ok, I've never used github before, so I may need to play around a little. My licensing will be as in free beer, so you are free to modify anything as you see fit. I'll find the way to plug that in.

You'll just need to include a commit in this pull request where you cp .license-assignments/template.md .license-assignments/temacube.md (and, of course, read and consent).

Likewise I noted (and was trying to get a handle on) the fact that "merge" doesn't do the "bubble-max-key" or "clojure.set/difference" performance hacks. It's probably not germane to a simple example, but could be important for large maps.

This might be worthy of an AsciiDoc Sidebar block on large maps. It'd be best to work on that in a separate branch/pull-request though.

@temacube
Copy link
Contributor Author

temacube commented Aug 2, 2013

I added the license agreement and reordered the reduce-kv addition.

I'll put other suggestions in distinct patch branches.

On Aug 2, 2013, at 9:01 AM, Ryan Neufeld notifications@github.com wrote:

Ok, I've never used github before, so I may need to play around a little. My licensing will be as in free beer, so you are free to modify anything as you see fit. I'll find the way to plug that in.

You'll just need to include a commit in this pull request where you cp .license-assignments/template.md .license-assignments/temacube.md (and, of course, read and consent).

Likewise I noted (and was trying to get a handle on) the fact that "merge" doesn't do the "bubble-max-key" or "clojure.set/difference" performance hacks. It's probably not germane to a simple example, but could be important for large maps.

This might be worthy of an AsciiDoc Sidebar block on large maps. It'd be best to work on that in a separate branch/pull-request though.


Reply to this email directly or view it on GitHub.

@qtrfeast
Copy link
Member

qtrfeast commented Aug 2, 2013

Thanks

qtrfeast pushed a commit that referenced this pull request Aug 2, 2013
Update applying-functions-to.asciidoc
@qtrfeast qtrfeast merged commit 94d7d18 into clojure-cookbook:master Aug 2, 2013
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

Successfully merging this pull request may close these issues.

2 participants