extend("test")
extend("array")

describe("array:filter", () => {

  it("filters out items that don’t satisfy the predicate", () => {
    result = array:filter(n => n > 10, [4,8,15,16,23,42])
    expect_equal(result, [15,16,23,42])
  })
  it("handles partial usage with only the predicate first", () => {
    myFilter = array:filter(n => n % 2 == 0)  # even-check
    expect_equal( myFilter([1,2,3,4,5]), [2,4] )
  })

  it("handles underscore for the predicate, array known", () => {
    partial = array:filter(_, [10,20,3,5])
    # Now we provide the predicate:
    result = partial(x => x < 10)
    expect_equal(result, [3,5])
  })

  it("allows a trivial predicate", () => {
    all = array:filter(_ => true, [1,2,3])
    expect_equal(all, [1,2,3])
  })

})
