pipes
This commit is contained in:
@@ -1360,5 +1360,22 @@ END;
|
||||
print("{}\n", pkg.hello()); // hello from testpkg
|
||||
}
|
||||
|
||||
// --- Pipe operator ---
|
||||
{
|
||||
print("--- pipe operator ---\n");
|
||||
// Basic: a |> f(b) → f(a, b)
|
||||
print("{}\n", 3 |> pkg.add(4)); // 7
|
||||
print("{}\n", 5 |> pkg.mul(6)); // 30
|
||||
|
||||
// Chaining: a |> f(b) |> g(c) → g(f(a, b), c)
|
||||
print("{}\n", 3 |> pkg.add(4) |> pkg.mul(2)); // 14
|
||||
|
||||
// With non-namespaced functions
|
||||
print("{}\n", "hello" |> concat(" world")); // hello world
|
||||
|
||||
// Chained string ops
|
||||
print("{}\n", "piped" |> concat(" ok") |> concat("!")); // piped ok!
|
||||
}
|
||||
|
||||
print("=== DONE ===\n");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user