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

@teleology/fp

Package Overview
Dependencies
Maintainers
1
Versions
26
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@teleology/fp

A small collection of functional programming utils

  • 1.0.8
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
29K
increased by13.61%
Maintainers
1
Weekly downloads
 
Created
Source

@teleology/fp

A collection of functional utilities supporting pipes

pipe

Accepts a variadic list of functions and passes one argument to the next from top-to-bottom.

Example:

const { pipe } = require('@teleology/fp');

const a = (s) => s - 12;
const b = (s) => s * 3;

pipe(
    a, 
    b, 
    console.log
)(10); // -6

compose

Accepts a variadic list of functions and passes one argument to the next from bottom-to-top.

Example:

const { compose } = require('@teleology/fp');

const a = (s) => s - 12;
const b = (s) => s * 3;

compose(
    console.log,
    a, 
    b
)(10); // 18

parallel

Accepts a variadic list of functions and returns a curried function. The curried function can then be invoked and will delegate its arguments in parallel across the functions.

Example:

const { parallel } = require('@teleology/fp');
const logDb = require('./apis/logs');

// Writes to both local logs as well as to our external api
const logger = parallel(
    logDb,
    console.log
);

logger({
    source: 'app',
    action: 'clicked login',
    time: Date.now(),
});

toss

Curries an error message returning an invocable function to throw. The invocable function can accept params to assign additional data to the Error.

Example:

const { toss } = require('@teleology/fp');

toss('An error occured')({ code: 403, reason: 'Entity already exists' });
// Error: An error occured
//     ...
//     at internal/main/run_main_module.js:17:47 {
//   code: 403, 
//   reason: 'Entity already exists'
// }

pick

Curry a dot notation path and default value, returns an invocable function requiring a target object.

Example:

const { pick } = require('@teleology/fp');

pick('[0].a.b')([
  {
    a: {
      b: 'hello',
    },
  },
]); // hello

map

A curried map function to be invoked within an Array.

Example:

const { map } = require('@teleology/fp');

map((a) => a.id)([
  {
    id: '1',
  },
  {
    id: '2',
  },
]); // [ '1', '2' ]

filter

A curried filter function to be invoked within an Array.

Example:

const { filter } = require('@teleology/fp');

filter((a) => a.id === '1')([
  {
    id: '1',
  },
  {
    id: '2',
  },
]); // [ { id: '1' } ]

find

A curried find function to be invoked within an Array.

Example:

const { find } = require('@teleology/fp');

find((a) => a.id === '1')([
  {
    id: '1',
  },
  {
    id: '2',
  },
]); // { id: '1' }

clean

Recursively removes empty values. An empty value is: null, empty string, undefined, an empty array or object.

Example:

const { clean } = require('@teleology/fp');

clean({
  a: null,
  b: '',
  c: undefined,
  d: {},
  e: [],
  f: 'hello',

  nested: { will: { be: { removed: {} } } },
}); // { f: 'hello' }

nonce

Wraps a function and prevents it from being called more than n times. Optional second params is the number of times, default is once.

Example:

const { nonce } = require('@teleology/fp');

const log = nonce(console.log);

log('hi'); // hi
log('bonjour');

Changelog

1.0.6

  • Adding once function

1.0.4

  • Adding a clean function to remove empty values

1.0.1

  • Renaming broadcast to parallel
  • Added find, filter functions
  • Updated README with examples
  • Updated toss to be invoked later to capture param

FAQs

Package last updated on 23 Feb 2021

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