New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

result4t

Package Overview
Dependencies
Maintainers
1
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

result4t

result4t

  • 0.7.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

result4t

Available now

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();

Keywords

FAQs

Package last updated on 29 Nov 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc