#!/usr/bin/ruby

func increment(n) {
    n+1
}

func double(n) {
    2*n
}

func triple(n) {
    3*n
}

var a = increment(double(triple(42)))
var b = (42 |> triple |> double |> increment)
var c = [triple, double, increment].reduce({|a,b| b(a) }, 42)

assert_eq(a, b)
assert_eq(a, c)

func foo(a,b) { a + b }

# Pass additional arguments to the given function
assert_eq(42 |> (foo, 3), 45)

# Call a method on the self-object, with optional arguments
assert_eq([1,2,3] |> (:map, { _*_ }), [1, 4, 9])

assert_eq(42 |> [:ipow, 3], 42**3)
assert_eq(42 |> (:ipow, 3), 42**3)

assert_eq(42 |> (:ipow, 6) |> :icbrt, 42**2)
assert_eq(42 |> (:ipow, 6) |> [:icbrt], 42**2)
assert_eq(42 |> (:ipow, 6) |> {.icbrt}, 42**2)
assert_eq(42 |> (:ipow, 6) |> (:iroot, 3), 42**2)
assert_eq(42 |> (:ipow, 6) |> [:iroot, 3], 42**2)
assert_eq(42 |> [:ipow, 6] |> [:iroot, 3], 42**2)

say "** Test passed!"
