Skip to content

Latest commit

 

History

History
47 lines (36 loc) · 819 Bytes

prefer-bimap.md

File metadata and controls

47 lines (36 loc) · 819 Bytes

Replace map + mapLeft with bimap (fp-ts/prefer-bimap)

Suggest replacing the combination of map followed by mapLeft (or vice-versa) with bimap.

💡 Fixable: This rule provides in-editor suggested fixes.

Rule Details

Examples of incorrect code for this rule:

import { pipe } from "fp-ts/function";
import { either } from "fp-ts";

pipe(
  getResult(),
  either.map((a) => a + 1),
  either.mapLeft((e) => e + 1)
);
import { pipe } from "fp-ts/function";
import { either } from "fp-ts";

pipe(
  getResult(),
  either.mapLeft((e) => e + 1),
  either.map((a) => a + 1)
);

Example of correct code for this rule:

import { pipe } from "fp-ts/function";
import { either } from "fp-ts";

pipe(
  getResult(),
  either.bimap(
    (e) => e + 1,
    (a) => a + 1
  )
);