Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

folktale

Package Overview
Dependencies
Maintainers
2
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

folktale

A suite of libraries for generic functional programming in JavaScript that allows you to write elegant modular applications with fewer bugs and more reuse.

  • 3.0.1-ts
  • tstypes
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
45K
decreased by-56.53%
Maintainers
2
Weekly downloads
 
Created

What is folktale?

Folktale is a standard library for functional programming in JavaScript. It provides a set of tools to help developers write more predictable and maintainable code by using functional programming patterns.

What are folktale's main functionalities?

Data.Task

Data.Task is used for handling asynchronous operations in a functional way. It allows you to compose tasks and handle success and failure cases explicitly.

const { task } = require('folktale/concurrency/task');

const readFile = (filename) => task(resolver => {
  require('fs').readFile(filename, 'utf8', (err, data) => {
    if (err) resolver.reject(err);
    else resolver.resolve(data);
  });
});

readFile('example.txt').run().listen({
  onRejected: (error) => console.error('Error:', error),
  onResolved: (data) => console.log('File content:', data)
});

Data.Maybe

Data.Maybe is used to represent optional values. It helps in avoiding null or undefined values by providing a way to handle the presence or absence of a value explicitly.

const { Just, Nothing } = require('folktale/maybe');

const findUser = (username) => {
  const users = { alice: 'Alice', bob: 'Bob' };
  return users[username] ? Just(users[username]) : Nothing();
};

const user = findUser('alice');
user.matchWith({
  Just: ({ value }) => console.log('User found:', value),
  Nothing: () => console.log('User not found')
});

Data.Either

Data.Either is used for computations that can fail. It represents a value that can be either a success (Right) or a failure (Left), allowing you to handle both cases explicitly.

const { Left, Right } = require('folktale/either');

const parseJSON = (jsonString) => {
  try {
    return Right(JSON.parse(jsonString));
  } catch (e) {
    return Left(e.message);
  }
};

const result = parseJSON('{ "name": "Alice" }');
result.matchWith({
  Right: ({ value }) => console.log('Parsed JSON:', value),
  Left: ({ value }) => console.log('Error:', value)
});

Other packages similar to folktale

Keywords

FAQs

Package last updated on 18 Feb 2018

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