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

powerfp

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

powerfp

Functional programming utils

  • 0.0.3
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

Installation

npm install powerfp

Features

  • implementation of useful algebraic data types: Option, Result, ResultS, Tree, List
  • utility functions used for function composition: compose, pipe, curry
  • infrastructure for the implementation of functors, monads and applicative functors in TypeScript
  • functors, monads and applicative functors implementation for algebraic data type (Option, Result, ResultS, Tree, List) and other commonly used types (Array, Promise, Iterable, Observable, IO)
  • do Haskell notation using ES6 generators
  • code generators for algebraic data types and functors, monads and applicative functors
  • utility functions like memoize and functions extracted from types like string, Regex (useful with function composition)
  • SumType type inferring ADT type from the constructor functions
  • matchValue predicate function matching single value against specified pattern (primitive values, object, array)
  • match function providing "pattern matching" functionality
  • toOption converting value of type T|null|undefined into Option<T>

Sample code

import { Option, none, some } from "powerfp";

function tryParseNumber(text: string): Option<number> {
  const n = Number(text);
  return Number.isNaN(n) ? none : some(n);
}


// ** powerfp**
type Option<T> =        
  | { type: "some", value: T }
  | { type: "none" };   
import { matchUnion, isUnion } from "powerfp";

function format(n: Option<number>) : string{
    return matchUnion(n, {
        some: ({ value }) => `${Math.round(value)} zl`,
        none: () => "0 zl"        
    });
}

const o: Option<number> = ...;
console.log(isUnion(o, "some") ? o.value : "");

more detailed documentation coming soon ..

FAQs

Package last updated on 10 Feb 2020

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