extend("test")
extend("array")
extend("math")
describe("array:map", () => {
it("maps int array with a doubling function", () => {
result = array:map(x => x * 2, [1,2,3,4])
expect_equal(result, [2,4,6,8])
})
it("supports partial usage for the mapping function", () => {
plusTenEach = array:map(n => n + 10)
expect_equal( plusTenEach([1,2,3]), [11,12,13] )
})
it("supports underscore for the first argument, array is known", () => {
partial = array:map(_, [1,5,10])
out = partial(x => x * 100)
expect_equal(out, [100,500,1000])
})
it("can handle a float array if supported", () => {
result = array:map(f => f + 0.5, [1.0,2.5,3.5])
expect_equal(result, [1.5,3.0,4.0])
})
})