Function matchOption

  • Takes a (lazy) default value, a function, and an Option value, if the Option value is None the default value is returned, otherwise the function is applied to the value inside the Some and the result is returned.

    Type Parameters

    • A
    • B

    Parameters

    • onNone: LazyArg<B>
    • onSome: ((a) => B)
        • (a): B
        • Parameters

          Returns B

    Returns ((ma) => B)

      • (ma): B
      • Parameters

        • ma: Option<A>

        Returns B

    Example

    import { some, none, match } from 'fp-ts/Option'
    import { pipe } from 'fp-ts/function'

    assert.strictEqual(
    pipe(
    some(1),
    match(() => 'a none', a => `a some containing ${a}`)
    ),
    'a some containing 1'
    )

    assert.strictEqual(
    pipe(
    none,
    match(() => 'a none', a => `a some containing ${a}`)
    ),
    'a none'
    )

    Since

    2.10.0