ceth
ceth

Reputation: 45295

Function composition or pipe operator

I have two functions:

user=> (def tmp (classificator.db/get-questions classificator.db/db))
#'user/tmp
user=> (def result (map classificator.core/transform-data tmp))
#'user/result

First function return data which I pass to second function.

I would like to write in one expression without tmp variable:

user=> (-> (classificator.db/get-questions classificator.db/db) (map classificator.core/transform-data))

IllegalArgumentException Don't know how to create ISeq from: classificator.core$transform_data  clojure.lang.RT.seqFrom (RT.java:542)

Looks like I don't mistake in the -> macros usage. How can I fix it?

Upvotes: 0

Views: 237

Answers (1)

Lee
Lee

Reputation: 144126

The thread-first macro -> puts arguments in the first position of the remaining forms, but you want it to go at the end. You can use the thread-last macro ->> instead:

(->> (classificator.db/get-questions classificator.db/db) 
     (map classificator.core/transform-data))

or

(->> classificator.db/db
     (classificator.db/get-questions)
     (map classificator.core/transform-data)))

Upvotes: 2

Related Questions