FP-TS

TE.chainFirst(f: (a: A) => TaskEither<E, B>):TaskEither<E, A> //处理右值不返回新右值
TE.chainFirst(() =>
      TE.fromIO(() =>
        logger.info('Log info', {})
      )
),
------------------------------------------------------------------------------
TE.chain(f: (a: A) => TaskEither<E, B>):TaskEither<E, B>//处理右值返回新右值
TE.chain(v =>TE.fromPredicate(
        () => true,
        () => e
      )(v)
    ),
TE.chainFirst(v =>TE.fromPredicate(
        () => true,
        () => e
      )(v)
    ), //不考虑右值
------------------------------------------------------------------------------
TE.map(f: (a: A) => B):TaskEither<E, B>
TE.chainFirstEitherK(f: (a: A) => E.Either<E, B>):TaskEither<E, B>

------------------------------------------------------------------------------
TE.bind('funcName', f: (a: A) => TaskEither<E, B>)
TE.let('funcName',f: (a: A) => B)

Handle Left Value

TE

//左值1=>左值2
TE.tapError(e1 =>e2)
//左值=>左值|右值 根据条件
TE.orElse(appError => {
  if (true) {
    return TE.right({});
  }
  return TE.left({});
})

E

E.mapLeft(f: (e: E) => G)):Either<G,_>

Conversion of Types

TE.fromEither(either)  Either->TE

import * as O from 'fp-ts/Option';
O.fromNullable(A|null) null=>O

TE.fromOption(option) O->TE

import * as T from 'fp-ts/Task';
const a =T.Task<void>
TE.fromTask(a) 

Last updated: 2026-03-20 14:11:04Scala/HTTP4s/Cats
Author:Chaolocation:https://www.baidu.com/article/36
Comments
Submit
Be the first one to write a comment ~