// Build from the repository root:
// build/flecha build examples/callback_algorithms.fl \
// --lib std=std/src -o /tmp/flecha-callback-algorithms
// Returns 42 after exercising every v0.2.0 callback form.
module callback_algorithms;
:: lib::std::containers::collections;
bool is_greater_than_two(&const i32 value) {
[4]i32 values = [1, 2, 3, 4];
collections::find_if<i32>(values[:], is_greater_than_two);
if !found or index != 2 {
// Captureless, contextually inferred anonymous function.
total := collections::fold<i32, i32>(
(sum, value) => { return sum + *value; }
// Capturing anonymous function.
collections::for_each<i32>(values[:], [&visited](value) => {
visited = visited + *value;
// Captureless comparator.
collections::sort_by<i32>(values[:], (left, right) => {
if values[0] != 4 or values[1] != 3 or
values[2] != 2 or values[3] != 1 {