-
Notifications
You must be signed in to change notification settings - Fork 103
Add Navigators for Sorted Sequences #317
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
base: master
Are you sure you want to change the base?
Changes from 3 commits
7abc71b
c309fdb
499d1b6
6063e1a
79f93e5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -546,6 +546,16 @@ | |
| res | ||
| )))) | ||
|
|
||
| (defn sorted-transform* | ||
| [structure keyfn comparator next-fn] | ||
| (let [sorted (sort-by (comp keyfn second) comparator (map-indexed vector structure)) | ||
| indices (map first sorted) | ||
| result (next-fn (map second sorted)) | ||
| unsorted (sort-by first compare (map vector (concat indices (repeat ##Inf)) result))] | ||
| (into (empty structure) | ||
|
||
| (map second) | ||
| unsorted))) | ||
|
|
||
| (defn- matching-indices [aseq p] | ||
| (keep-indexed (fn [i e] (if (p e) i)) aseq)) | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Either the naming or implementation here is off. As named, this isn't accepting general paths but only a key. In this case, it's wrong to use
late-pathand it will be more straightforward/faster to usegetrather thancompiled-select. Additionally,compiled-selectreturns a sequence of results which I don't think you want to be comparing against.An alternative is to have the first arg be an "extractor path", and use
compiled-select-one!to extract the key. This would allow for usage where the desired comparator key is nested or transformed, like(sorted-by [:a :b (view -)])There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, my intention was to have it be a generic full path, what you're calling an extractor path. I thought
keypathwould be an appropriate term here since inclojure.core/sort-bythe argument is called thekeyfn. I'll change this to usecompiled-select-one!.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've updated this to use compiled-select-one!. Would you recommend I also rename the keypath, or is this enough?