takeif

.takeif value:{Dynamic} condition:{Lambda} -> Any

Keeps value if condition is true, otherwise returns none.

Note: this function is usually inlined. When inlining lambda arguments, an explicit @lambda annotation is required:

.takeif {5} {@lambda x: .iseven {.x}}

This function is particularly useful when chained, for example:

.sum {2} {3}::takeif {@lambda x: .iseven {.x}}::otherwise {0}

Return

value if the result of condition is true, none otherwise

Parameters

value

value to check

condition

condition to check, which accepts one argument (value) and returns a boolean