0.7.0 • Published 5 months ago

result4t v0.7.0

Weekly downloads
-
License
MIT
Repository
github
Last release
5 months ago

pnpm add @ollierelph/result4t or pnpm add result4t

What's this?

result4t takes some pointers from the wonderful result4k

It's a replacement for Promise that gives us a strongly-typed error mode.

An example

import fs from "node:fs";

const readFileAndReverse = () =>
  fs
    .readFile("./boom.txt")
    .then((contents) => contents.split("\n").reverse().join("\n"));

readFileAndReverse()
  .then((reversedFile) => {
    console.log(reversedFile);
    process.exit(0);
  })
  .catch((error: unknown) => {
    console.error(error);
    process.exit(1);
  });

in result4t:

import fs from "node:fs";
import { TaskResult } from "./TaskResult";

const readFileAndReverse = () =>
  TaskResult.ofPromise(
    () => fs.readFile("./boom.txt"),
    (err: unknown) => new Error("Unable to find file"),
  ).map((contents) => contents.split("\n").reverse().join("\n"));

readFileAndReverse()
  .peek((reversedFile) => {
    console.log(reversedFile);
    process.exit(0);
  })
  .peekLeft((error) => {
    // ^--- typed as Error
    console.error(error);
    process.exit(1);
  })
  .run();
0.5.4

5 months ago

0.5.3

5 months ago

0.5.6

5 months ago

0.5.5

5 months ago

0.5.0

5 months ago

0.4.0

5 months ago

0.7.0

5 months ago

0.6.0

5 months ago

0.5.1

5 months ago

0.3.0

11 months ago

0.2.4

1 year ago

0.2.3

1 year ago

0.2.2

1 year ago

0.2.1

1 year ago

0.2.0

1 year ago

0.1.0

1 year ago

0.0.7

1 year ago

0.0.6

1 year ago

0.0.5

1 year ago

0.0.4

1 year ago

0.0.3

1 year ago