-
-
Notifications
You must be signed in to change notification settings - Fork 463
-
Hello,
I would like to know how to add a function accepting closure as an argument.
For example, I want to create a function flatten( something, { #.some_field }):
somethingwould be a[]map[string]string- and it would return a
[]stringcontaining thesome_fieldvalues found in thesomethingarray
To achieve this, I believe closure would be the best way. Is it something that can be done ? (I didn't find other examples except the builtins all/one/etc. but I don't see how to transpose this to a function I could expose).
Thanks!
Beta Was this translation helpful? Give feedback.
All reactions
Replies: 1 comment 3 replies
-
You can just use this:
map(something, .some_field)
Brackets { and }, as well as # char is optional.
Beta Was this translation helpful? Give feedback.
All reactions
-
Hello,
Sorry, the flatten was just an example.
My question is really how/if I can create a function that accepts closure argument 😄
Thanks and sorry if the question was unclear
Beta Was this translation helpful? Give feedback.
All reactions
-
This is not possible. Those predicates (all, none, map, filter, etc) and closures are tight together. Think of them as language keywords (like for, while, do {...} while).
It may be cool to add some API to allow to use closures somehow.
What is your use case? What kind of problem you trying to solve?
Beta Was this translation helpful? Give feedback.
All reactions
-
I was looking at the same today. My specific usecause is for a custom filter/count/sum where I want the closure to be a predicate pushdown to the left-hand side, which is a function, that does some sql queries. I was wondering what the most ergonomic way to implement this would be.
I primarily want to avoid moving data unnecessarily.
Beta Was this translation helpful? Give feedback.