@mikuroxina/mini-fn
    Preparing search index...

    Variable flatMapConst

    flatMap: <T, U>(
        optB: (t: T) => Option.Option<U>,
    ) => (optA: Option.Option<T>) => Option.Option<U> = andThen

    The alias of andThen.

    Type Declaration

      • <T, U>(
            optB: (t: T) => Option.Option<U>,
        ): (optA: Option.Option<T>) => Option.Option<U>
      • Returns None if optA is None, otherwise calls optB and return the result. This is an implementation of FlatMap. The order of arguments is reversed because of that it is useful for partial applying.

        Type Parameters

        • T
        • U

        Parameters

        • optB: (t: T) => Option.Option<U>

          The function returns second optional when used optA is Some.

        Returns (optA: Option.Option<T>) => Option.Option<U>

        optB or a None.

        Examples

        const sqrtThenToString = (num: number): Option<string> =>
        0 <= num ? some(Math.sqrt(num).toString()) : none();

        const applied = andThen(sqrtThenToString);
        expect(applied(some(4))).toStrictEqual(some("2"));
        expect(applied(some(-1))).toStrictEqual(none());
        expect(applied(none())).toStrictEqual(none());