Skip to content

Suggested addition: index-and-map-by #50

Description

@vvvvalvalval

Wondering if you'd be open to a function index-and-map-by generalizing over index-by like the following:

(defn index-and-map-by
  [kf vf coll]
  (into {} 
    (map 
      (fn [x]
        [(kf x) (vf x)]))
    coll))

(Of course, you might want to improve the peformance of this implementation, e.g with reduce and transients).

(index-and-map-by kf vf coll) would be equivalent to (->> coll (index-by kf) (map-vals vf))

I'm asking because I keep defining this index-and-map-by function in my projects.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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