Renamed getByWithFn

This commit is contained in:
Ozzie Gooen 2022-08-31 19:56:12 -07:00
parent cd20bef11d
commit 6631c9bad7
2 changed files with 7 additions and 7 deletions

View File

@ -1,21 +1,21 @@
open Jest
open TestHelpers
describe("E.A.getByWithFn", () => {
makeTest("Empty list returns None", E.A.getByWithFn([], x => x + 1, x => mod(x, 2) == 0), None)
describe("E.A.getByFmap", () => {
makeTest("Empty list returns None", E.A.getByFmap([], x => x + 1, x => mod(x, 2) == 0), None)
makeTest(
"Never predicate returns None",
E.A.getByWithFn([1, 2, 3, 4, 5, 6], x => x + 1, _ => false),
E.A.getByFmap([1, 2, 3, 4, 5, 6], x => x + 1, _ => false),
None,
)
makeTest(
"function evaluates",
E.A.getByWithFn([1, 1, 1, 1, 1, 1, 1, 2, 1, 1], x => 3 * x, x => x > 4),
E.A.getByFmap([1, 1, 1, 1, 1, 1, 1, 2, 1, 1], x => 3 * x, x => x > 4),
Some(6),
)
makeTest(
"always predicate returns fn(fst(a))",
E.A.getByWithFn([0, 1, 2, 3, 4, 5, 6], x => 10 + x, _ => true),
E.A.getByFmap([0, 1, 2, 3, 4, 5, 6], x => 10 + x, _ => true),
Some(10),
)
})

View File

@ -572,7 +572,7 @@ module A = {
|> (x => Ok(x))
}
let getByWithFn = (a, fn, boolCondition) => {
let getByFmap = (a, fn, boolCondition) => {
let i = ref(0)
let finalFunctionValue = ref(None)
let length = Belt.Array.length(a)
@ -690,7 +690,7 @@ module A = {
let firstSome = x => Belt.Array.getBy(x, O.isSome)
let firstSomeFn = (r: array<unit => option<'a>>): option<'a> =>
O.flatten(getByWithFn(r, l => l(), O.isSome))
O.flatten(getByFmap(r, l => l(), O.isSome))
let firstSomeFnWithDefault = (r, default) => firstSomeFn(r)->O2.default(default)