Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

REQUEST - support user defined functions #25

Closed
maded2 opened this issue Aug 10, 2016 · 6 comments
Closed

REQUEST - support user defined functions #25

maded2 opened this issue Aug 10, 2016 · 6 comments
Assignees

Comments

@maded2
Copy link

maded2 commented Aug 10, 2016

hi, this library is great. User defined parameters/variables is very welcome. Is there any chance you can add user defined functions as well (ideally nested user defined functions).

example:

"(requests_made("5m") * requests_succeeded("5m") / 100) >= 90"

@vjeantet
Copy link

That could be a killer feature, I like that !

@Knetic Knetic self-assigned this Aug 11, 2016
@Knetic
Copy link
Owner

Knetic commented Aug 12, 2016

Thanks for using the library! I've thought about adding support for this before, but never did it because I generally found that any function I could want to call could just as easily be called before the expression was evaluated, with the result passed as a parameter.

However, I know that may not be feasible for some advanced use cases, and your example of something that aggregates data within the expression was pretty compelling. Also, like three people all voted for this at once (which I think makes this the most popular issue on the project 😛 ), so I sat down and implemented it as of db7388b .

@Knetic Knetic closed this as completed Aug 12, 2016
@maded2
Copy link
Author

maded2 commented Aug 12, 2016

thanks for the quick turnaround, will try out very soon. Does it support nested user-defined function?

@Knetic
Copy link
Owner

Knetic commented Aug 12, 2016

There's some explanation on usage in the readme - but yes, it does support nesting. You can give a function any number of arguments, and include any other operations you like. For example; the following expression is perfectly valid and will work like expected (assuming the proper function/parameters are passed in):

    // returns the largest of the three parameters. The middle gets the absolute value of 'anotherValue'
    "max(someValue, abs(anotherValue), 10 * lastValue)"

@maded2
Copy link
Author

maded2 commented Aug 12, 2016

this is great, many thanks.

@emirigoyen
Copy link

Good day ....
Query: Is there a mechanism to nest user-defined functions dynamically? That is, to build compound functions defined by the user, type f (g (h (x + 4)))? with f, g and h user-defined functions dynamically?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants