Runs a function if value is valid (not null or undefined), and returns the result as an Option.
value
The value to validate.
The function to run if value is valid.
Some(fn()) if value is valid, otherwise None().
Some(fn())
None()
const maybeName = ifValid("Jane", () => "Hello, Jane");// maybeName.kind === "some"const maybeNothing = ifValid(null, () => "This won't run");// maybeNothing.kind === "none" Copy
const maybeName = ifValid("Jane", () => "Hello, Jane");// maybeName.kind === "some"const maybeNothing = ifValid(null, () => "This won't run");// maybeNothing.kind === "none"
Runs a function if
valueis valid (not null or undefined), and returns the result as an Option.