Pass a function as a parameter via catalog

32 views
Skip to first unread message

Anuj Kumar

unread,
Nov 19, 2016, 2:00:04 PM11/19/16
to Onyx
Hi,

Is it possible to add a function as a parameter to the catalog?

For example, I have a filter function where I need to pass an external function as a parameter that can be used within the function defined as :onyx/type :function.

Sample function-

(defn filter-word [ffn segment]
   (filter #(ffn (:count %)) (vector segment)))

where catalog has an entry-

{:onyx/name :odd
 :onyx/fn :play.onyx.play-wordcount/filter-word
 :onyx/type :function
 :parameterized.core/ffn odd?
 :onyx/params [:parameterized.core/ffn]
 :onyx/batch-size 10}

Thanks,
Anuj

Mike Drogalis

unread,
Nov 19, 2016, 3:19:07 PM11/19/16
to Anuj Kumar, Onyx
Hi Anuj,

Since jobs must be EDN serializable, you can't pass a function as a parameter to the catalog using :onyx/params. You can, however, use another technique for injecting parameters into a function as described here in the User Guide.

Essentially you want to write a lifecycle that adds the filter function as a parameter to your function. We have an example of this here in onyx-examples.

--
You received this message because you are subscribed to the Google Groups "Onyx" group.
To unsubscribe from this group and stop receiving emails from it, send an email to onyx-user+unsubscribe@googlegroups.com.
To post to this group, send email to onyx...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/onyx-user/CAGUDQMzHasduF8LFV_JwyDvXxGf%2B-ny1iBUDcqaEuSwGOWoM_Q%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Anuj Kumar

unread,
Nov 19, 2016, 3:35:46 PM11/19/16
to Mike Drogalis, Onyx
Thanks Mike. That helps.

Reply all
Reply to author
Forward
0 new messages