@pathmaker-digital/pmd-utilities - v2.2.6
    Preparing search index...

    Function ifValid

    • Runs a function if value is valid (not null or undefined), and returns the result as an Option.

      Type Parameters

      • T
      • K

      Parameters

      • value: T

        The value to validate.

      • fn: () => K

        The function to run if value is valid.

      Returns Option<K>

      Some(fn()) if value is valid, otherwise None().

      const maybeName = ifValid("Jane", () => "Hello, Jane");
      // maybeName.kind === "some"

      const maybeNothing = ifValid(null, () => "This won't run");
      // maybeNothing.kind === "none"