1

How can I apply multiple functions, each producing a single map, to a common parameter, then merge all results? Can this be improved?

(merge {} (podr root) (version root) (year root) (month root))

where root is the common argument and podr, version, year and month are the functions.

2 Answers 2

5

You can create a seq of functions and use map to apply each one to root:

(into {} (map #(% root) [podr version year month]))

Or, you can use juxt to achieve the same:

(into {} ((juxt podr version year month) root))

Both are more or less equal.

Sign up to request clarification or add additional context in comments.

Comments

0

Map application over a list of functions.

E.g. in Haskell it would be:

> map (\f -> f 2) [(+1), (*2), (^3)]
[3,4,8]

Or, using ($) as f $ x = f x you can apply :

> map ($ 2) [(+1), (*2), (^3)]
[3,4,8]

Same approach in any language with first class functions and application.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.