Skip to content

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

@vvvvalvalval

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.

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