@jenova-marie/ts-rust-result - v2.2.12
    Preparing search index...

    Function map

    • Maps a successful Result value using the provided function. If the Result is an error, returns the error unchanged.

      Type Parameters

      • T

        The type of the input value

      • U

        The type of the output value

      • E = Error

        The type of the error

      Parameters

      • result: Result<T, E>

        The Result to map

      • fn: (value: T) => U

        Function to transform the successful value

      Returns Result<U, E>

      A new Result with the transformed value, or the original error

      const result = ok(5)
      const doubled = map(result, x => x * 2) // ok(10)

      const errorResult = err(new Error("Failed"))
      const mapped = map(errorResult, x => x * 2) // err(Error("Failed"))