New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

basefp

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

basefp

The hassle-free way to apply functional programming principles in JavaScript

latest
Source
npmnpm
Version
0.0.5
Version published
Maintainers
1
Created
Source

basefp

For those who want to stay small and nimble

Inspired by https://medium.com/javascript-inside/effective-data-validation-in-javascript-5c2f3e75249e

API

module.exports = {
  asyncPipe,  // asyncPipe  :: Foldable f => f (a -> Promise) -> a -> Promise a Error
  pipe,       // pipe       :: Foldable f => f (Any -> Any) -> a -> b
  compose,    // compose    :: (b -> c) -> (a -> b) -> (a -> c)
  map,        // map        :: Functor f => (a -> b) -> f a -> f b
  filter,     // filter     :: Filterable f => (a -> Boolean) -> f a -> f a
  reduce,     // reduce     :: Foldable f => (b, a -> b) -> b -> f a -> b
  encase,     // encase     :: DefaultValue -> (a -> b) -> DefaultValue || b
  log,        // log        :: a -> IO a
  recover,    // recover    :: DefaultValue -> a -> DefaultValue || a
}

Example

const user = {
  name: "Dimitri",
  cities: ["Berlin", "Stuttgart"]
}

const pipeline = pipe([
   // encase :: DefaultValue -> (a -> b) -> DefaultValue || b
      encase ("San Francisco") (x => x.cities[5]),
   // map :: (a -> b) -> a -> b
      map (x => x.toUpperCase()),
   // encase :: DefaultValue -> (a -> b) -> DefaultValue || b
      encase ("B") (str => str.charAt(0)),
   // recover :: DefaultValue -> a -> DefaultValue || a
      recover ("Nothing")
    ]) (user),

console.log(pipeline) // "S"

Keywords

functional programming

FAQs

Package last updated on 17 May 2019

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