Core standard library functions for the Flap programming language.
Checks if a value exists in a list using tail recursion.
Parameters:
list- The list to search invalue- The value to find
Returns: 1 (yes) if found, 0 (no) if not found
Example:
contains([1, 2, 3], 2) // -> 1 (yes)
contains([1, 2, 3], 4) // -> 0 (no)
Keeps only elements where predicate returns yes.
Parameters:
pred- A predicate functionlist- The list to filter
Example:
filter(x => x > 2, [1, 2, 3, 4]) // -> [3, 4]
Applies a function to each element of a list.
Parameters:
f- The function to applylist- The list to map over
Example:
map(x => x * 2, [1, 2, 3]) // -> [2, 4, 6]
Folds a list with a binary function and initial value using tail recursion.
Parameters:
f- Binary function taking accumulator and current elementlist- The list to reduceinit- Initial accumulator value
Example:
reduce(acc, x => acc + x, [1, 2, 3, 4], 0) // -> 10
Reverses a list using slice notation.
Parameters:
list- The list to reverse
Example:
reverse([1, 2, 3]) // -> [3, 2, 1]
- License: BSD-3