Socket
Socket
Sign inDemoInstall

fxjs2

Package Overview
Dependencies
1
Maintainers
1
Versions
62
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    fxjs2

Functional Extensions for Javascript


Version published
Weekly downloads
41
Maintainers
1
Install size
315 kB
Created
Weekly downloads
 

Readme

Source

FxJS - Functional Extensions for Javascript

ES6+에서 사용하는 함수형 라이브러리

설치

npm i fxjs2

목차

  • map
  • filter
  • reduce
  • take
  • L.map
  • L.filter
  • go
map
map(a => a + 10, [1, 2, 3]);
// [11, 12, 13]
filter
filter(a => a % 2, [1, 2, 3]);
// [1, 3]
reduce
const add = (a, b) => a + b
reduce(add, [1, 2, 3]);
// 6

reduce(add, 10, [1, 2, 3]);
// 16

reduce(add, {a: 1, b: 2, c: 3});
// 6

await reduce(add, [Promise.resolve(1), 2, 3])
// 6
take
take(1, [1, 2, 3]);
// [1]

take(2, [1, 2, 3])
// [1, 2]
L.map
const lazy = L.map(a => a + 10, [1, 2, 3]);
take(2, lazy);
// [11, 12]
L.filter
const lazy = L.filter(a => a % 2, [1, 2, 3, 4, 5]);
take(2, lazy);
// [1, 3]
const lazy = L.filter(a => a % 2, L.map(a => a + 10, [1, 2, 3, 4, 5]));
take(2, lazy);
// [11, 13]
go
const b = go(
  0,
  a => a + 1,
  a => a + 10,
  a => a + 100);

console.log(b);
// 111

try {
  const b = go(
    0,
    a => { throw { hi: 'ho' } },
    a => a + 10,
    a => a + 100);

  console.log(b);
} catch (c) {
  console.log(c);
}
// { hi: 'ho' }

const b = await go(
  0,
  a => Promise.resolve(a + 1),
  a => a + 10,
  a => a + 100);

console.log(b);
// 111

try {
  const b = await go(
    0,
    a => Promise.resolve(a + 1),
    a => Promise.reject({ hi: 'ho' }),
    a => a + 100);

  console.log(b);
} catch (c) {
  console.log(c);
}
// { hi: 'ho' }

try {
  const b = await go(
    0,
    a => Promise.resolve(a + 1),
    a => Promise.reject({ hi: 'ho' }),
    a => a + 100);

  console.log(b);
} catch (c) {
  console.log(c);
}
// { hi: 'ho' }

FAQs

Last updated on 13 Dec 2018

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc