From b3e699b0969f510d27b28b78b41ed596d39b82ef Mon Sep 17 00:00:00 2001 From: Nicola Puppa Date: Tue, 5 Sep 2023 11:21:24 +0200 Subject: [PATCH] docs: add new assert function docs --- .../feel-built-in-functions-boolean.md | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/docs/docs/reference/builtin-functions/feel-built-in-functions-boolean.md b/docs/docs/reference/builtin-functions/feel-built-in-functions-boolean.md index c77832cbb..a2084cc97 100644 --- a/docs/docs/reference/builtin-functions/feel-built-in-functions-boolean.md +++ b/docs/docs/reference/builtin-functions/feel-built-in-functions-boolean.md @@ -80,3 +80,53 @@ get or default(null, "default") get or default(null, null) // null ``` + +## assert(value, condition) + + + +Verify that the provided condition is met, if the condition is true the function returns the value. Otherwise, the evaluation fails with an error + +**Function signature** + +```js +assert(value: Any, condition: Any) +``` + +**Examples** + +```js +assert(x, x > 3) with x = 4 +// 4 + +assert(x, x != null) with x = "value" +// "value" + +assert(x, x > 5) with x = 4 +// error("The condition is not fulfilled") +``` + +## assert(value, condition, cause) + + + +Verify that the provided condition is met, if the condition is true the function returns the value. Otherwise, the evaluation fails with an error and the provide error message + +**Function signature** + +```js +assert(value: Any, condition: Any, cause: String) +``` + +**Examples** + +```js +assert(x, x > 3, "Custom error message") with x = 4 +// 4 + +assert(x, x > 5, "Custom error message") with x = 4 +// error("Custom error message") + +assert(x, x != null, "Custom error message") with x = null +// error("Custom error message") +```