Security News
Combatting Alert Fatigue by Prioritizing Malicious Intent
In 2023, data breaches surged 78% from zero-day and supply chain attacks, but developers are still buried under alerts that are unable to prevent these threats.
FxJS is a functional programming library based on ECMAScript 6. Iterable, Iterator, Generator, Promise.
<script src="path/fx.min.js"></script>
<script src="path/fx.es5.min.js"></script>
The functions of FxJS are written in ECMAScript Module. Also, since each function is well separated into individual files, Tree-Shaking is possible when a bundler like a webpack is bundling.
npm install fxjs2
import { map, filter, reduce, L, C } from "fxjs2";
We use esm to import the FxJS functions created in the ECMAScript Module into the CommonJS Module.
const { map, filter, reduce, L, C } = require("fxjs2");
You can evaluate the iterator as a function of FxJS.
function *fibonacci() {
let a = 0, b = 1;
while (true) {
yield a;
[a, b] = [b, a + b];
}
}
const f = pipe(
fibonacci,
L.filter(n => n % 2 == 0),
L.takeWhile(n => n < 10));
const iterator = f();
console.log(iterator.next()); // { value: 0, done: false }
console.log(iterator.next()); // { value: 2, done: false }
console.log(iterator.next()); // { value: 8, done: false }
console.log(iterator.next()); // { value: undefined, done: true }
reduce((a, b) => a + b, f());
// 10
Any value can be used with FxJS if it has a [Symbol.iterator]()
method.
const res = go(
[1, 2, 3, 4, 5],
filter(a => a % 2),
reduce(add));
log(res); // 9
You can do 'lazy evaluation' as a function of the L
namespace.
const res = go(
L.range(Infinity),
L.filter(a => a % 2),
L.take(3),
reduce(add));
log(res); // 9
Reactive functional programming style.
go(
L.range(Infinity),
L.map(delay(1000)),
L.map(a => a + 10),
L.take(3),
each(log));
// After 1 second 10
// After 2 seconds 11
// After 3 seconds 12
Asynchronous control is easy.
// L.interval = time => L.map(delay(time), L.range(Infinity));
await go(
L.interval(1000),
L.map(a => a + 30),
L.takeUntil(a => a == 33),
each(log));
// After 1 second 30
// After 2 seconds 31
// After 3 seconds 32
// After 4 seconds 33
const res = await go(
L.interval(1000),
L.map(a => a + 20),
L.takeWhile(a => a < 23),
L.map(tap(log)),
reduce(add));
// After 5 seconds 20
// After 6 seconds 21
// After 7 seconds 22
log(res);
// 63
C
functions can be evaluated concurrency.
await map(getPage, range(1, 5));
// After 4 seconds
// [page1, page2, page3, page4]
const pages = await C.map(getPage, range(1, 5));
// After 1 second
// [page1, page2, page3, page4]
Like Clojure Reducers, you can handle concurrency.
go(
range(1, 5),
map(getPage),
filter(page => page.line > 50),
map(getWords),
flat,
countBy(identity),
log);
// After 4 seconds
// { html: 78, css: 36, is: 192 ... }
go(
L.range(1, 5),
L.map(getPage),
L.filter(page => page.line > 50),
L.map(getWords),
C.takeAll, // All requests same time.
flat,
countBy(identity),
log);
// After 1 second
// { html: 78, css: 36, is: 192 ... }
go(
L.range(1, 5),
L.map(getPage),
L.filter(page => page.line > 50),
L.map(getWords),
C.takeAll(2), // 2 requests same time.
flat,
countBy(identity),
log);
// After 2 second
// { html: 78, css: 36, is: 192 ... }
You can use JavaScript standard error handling.
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' }
You can use async/await and try/catch to handle asynchronous error handling.
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' }
The following libraries are based on FxJS. These are libraries that can handle SQL and DOM through functional APIs, respectively.
FAQs
Functional Extensions for modern Javascript
The npm package fxjs2 receives a total of 25 weekly downloads. As such, fxjs2 popularity was classified as not popular.
We found that fxjs2 demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
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.
Security News
In 2023, data breaches surged 78% from zero-day and supply chain attacks, but developers are still buried under alerts that are unable to prevent these threats.
Security News
Solo open source maintainers face burnout and security challenges, with 60% unpaid and 60% considering quitting.
Security News
License exceptions modify the terms of open source licenses, impacting how software can be used, modified, and distributed. Developers should be aware of the legal implications of these exceptions.