Comparing version 0.2.7 to 0.9.0
14
C.js
@@ -15,2 +15,5 @@ import tailC from './Concurrency/tailC.js'; | ||
import dropC from "./Concurrency/dropC.js"; | ||
import compactC from "./Concurrency/compactC.js"; | ||
import takeRaceC from "./Concurrency/takeRaceC.js"; | ||
import raceC from "./Concurrency/raceC.js"; | ||
@@ -35,3 +38,7 @@ const C = { | ||
some: someC, | ||
drop: dropC | ||
drop: dropC, | ||
compact: compactC, | ||
takeRace: takeRaceC, | ||
take_race: takeRaceC, | ||
race: raceC | ||
}; | ||
@@ -54,3 +61,6 @@ | ||
someC, | ||
dropC | ||
dropC, | ||
compactC, | ||
takeRaceC, | ||
raceC | ||
} |
@@ -1,3 +0,5 @@ | ||
export default function call(a, f) { | ||
return f(a); | ||
} | ||
import curry from "./curry.js"; | ||
export default curry(function call(f, ...args) { | ||
return f(...args); | ||
}); |
@@ -1,2 +0,2 @@ | ||
import baseCalls from "./baseCalls.js"; | ||
import baseCalls from "./.internal/baseCalls.js"; | ||
import map from "./map.js"; | ||
@@ -3,0 +3,0 @@ import object from "./object.js"; |
@@ -1,2 +0,2 @@ | ||
import baseCalls from "../baseCalls.js"; | ||
import baseCalls from "../.internal/baseCalls.js"; | ||
import mapC from "./mapC.js"; | ||
@@ -3,0 +3,0 @@ import objectC from "./objectC.js"; |
@@ -1,8 +0,15 @@ | ||
import take1C from "./take1C.js"; | ||
import curry from "../curry.js"; | ||
import rejectLazy from "../Lazy/rejectLazy.js"; | ||
import go1 from "../go1.js"; | ||
import go from "../go.js"; | ||
import mapLazy from "../Lazy/mapLazy.js"; | ||
import takeUntilLazy from "../Lazy/takeUntilLazy.js"; | ||
import reduceC from "./reduceC.js"; | ||
import not from "../not.js"; | ||
export default curry(function everyC(f, iter) { | ||
return go1(take1C(rejectLazy(f, iter)), ({length}) => length == 0); | ||
});; | ||
return go( | ||
mapLazy(f, iter), | ||
takeUntilLazy(not), | ||
reduceC((a, b) => a && b), | ||
(a = false) => a, | ||
Boolean); | ||
}); |
@@ -1,8 +0,15 @@ | ||
import take1C from "./take1C.js"; | ||
import curry from "../curry.js"; | ||
import filterLazy from "../Lazy/filterLazy.js"; | ||
import go1 from "../go1.js"; | ||
import mapLazy from "../Lazy/mapLazy.js"; | ||
import takeUntilLazy from "../Lazy/takeUntilLazy.js"; | ||
import identity from "../identity.js"; | ||
import reduceC from "./reduceC.js"; | ||
import go from "../go.js"; | ||
export default curry(function someC(f, iter) { | ||
return go1(take1C(filterLazy(f, iter)), ({length}) => length == 1); | ||
return go( | ||
mapLazy(f, iter), | ||
takeUntilLazy(identity), | ||
reduceC((a, b) => a || b), | ||
(a = false) => a, | ||
Boolean); | ||
}); |
@@ -0,3 +1,24 @@ | ||
import toIter from "../toIter.js"; | ||
import go from "../go.js"; | ||
import map from "../map.js"; | ||
import rangeLazy from "../Lazy/rangeLazy.js"; | ||
import mapLazy from "../Lazy/mapLazy.js"; | ||
import takeUntilLazy from "../Lazy/takeUntilLazy.js"; | ||
import flat from "../flat.js"; | ||
import takeC from "./takeC.js"; | ||
import takeWhile from "../takeWhile.js"; | ||
export default takeC(Infinity); | ||
export default function takeAllC(n, iter) { | ||
if (arguments.length == 1) return typeof n == 'number' ? _ => takeAllC(n, _) : takeC(Infinity, n); | ||
iter = toIter(iter); | ||
let closed = false; | ||
return go( | ||
rangeLazy(Infinity), | ||
mapLazy(_ => go( | ||
rangeLazy(n), | ||
mapLazy(_ => iter.next()), | ||
takeWhile(({done}) => !(closed = done)), | ||
map(({value}) => value))), | ||
takeUntilLazy(_ => closed), | ||
flat); | ||
} |
@@ -1,2 +0,2 @@ | ||
import baseExtend from "./baseExtend.js"; | ||
import baseExtend from "./.internal/baseExtend.js"; | ||
import has from "./has.js"; | ||
@@ -3,0 +3,0 @@ |
import curry from "./curry.js"; | ||
export default curry(function delay(time, a) { | ||
return new Promise(resolve => setTimeout(() => resolve(a), time)); | ||
export default curry(async function delay(time, a) { | ||
await new Promise(resolve => setTimeout(resolve, time)); | ||
return a; | ||
}); |
14
every.js
@@ -1,8 +0,14 @@ | ||
import rejectLazy from "./Lazy/rejectLazy.js"; | ||
import take1 from "./take1.js"; | ||
import go1 from "./go1.js"; | ||
import curry from "./curry.js"; | ||
import go from "./go.js"; | ||
import { mapLazy, takeUntilLazy } from "./L.js"; | ||
import reduce from "./reduce.js"; | ||
import not from "./not.js"; | ||
export default curry(function every(f, iter) { | ||
return go1(take1(rejectLazy(f, iter)), ({length}) => length == 0); | ||
return go( | ||
mapLazy(f, iter), | ||
takeUntilLazy(not), | ||
reduce((a, b) => a && b), | ||
(a = false) => a, | ||
Boolean); | ||
}); |
@@ -1,2 +0,2 @@ | ||
import baseExtend from "./baseExtend.js"; | ||
import baseExtend from "./.internal/baseExtend.js"; | ||
@@ -3,0 +3,0 @@ const setter = (obj, [k, v]) => (obj[k] = v, obj); |
27
fx.js
@@ -32,3 +32,2 @@ export { default as minBy, default as min_by } from './minBy.js'; | ||
export { default as extend } from './extend.js'; | ||
export { default as empty } from './empty.js'; | ||
export { default as takeWhile, default as take_while } from './takeWhile.js'; | ||
@@ -50,2 +49,3 @@ export { default as isMatch, default as is_match } from './isMatch.js'; | ||
export { default as go1 } from './go1.js'; | ||
export { default as pipe1 } from './pipe1.js'; | ||
export { default as find } from './find.js'; | ||
@@ -79,5 +79,5 @@ export { default as isArray, default as is_array } from './isArray.js'; | ||
export { default as defaults } from './defaults.js'; | ||
export { default as apply } from './apply.js'; | ||
export { default as calls } from './calls.js'; | ||
export { default as delay } from './delay.js'; | ||
export { default as safety } from './safety.js'; | ||
export { default as mapObject, default as map_object } from './mapObject.js'; | ||
@@ -89,4 +89,27 @@ export { default as promiseAllObject, default as promise_all_object } from './promiseAllObject.js'; | ||
export { default as drop } from './drop.js'; | ||
export { default as dropWhile } from './dropWhile.js'; | ||
export { default as dropUntil } from './dropUntil.js'; | ||
export { default as dropRight, default as drop_right } from './dropRight.js'; | ||
export { default as difference } from './difference.js'; | ||
export { default as differenceBy } from './differenceBy.js'; | ||
export { default as differenceWith } from './differenceWith.js'; | ||
export { default as initial } from './initial.js'; | ||
export { default as rest } from './rest.js'; | ||
export { default as intersection } from './intersection.js'; | ||
export { default as intersectionBy } from './intersectionBy.js'; | ||
export { default as intersectionWith } from './intersectionWith.js'; | ||
export { default as unionBy } from './unionBy.js'; | ||
export { default as union } from './union.js'; | ||
export { default as zip } from './zip.js'; | ||
export { default as unzip } from './unzip.js'; | ||
export { default as zipObj } from './zipObj.js'; | ||
export { default as zipWith } from './zipWith.js'; | ||
export { default as partition } from './partition.js'; | ||
export { default as join } from './join.js'; | ||
export { default as html } from './html.js'; | ||
export { default as chunk } from './chunk.js'; | ||
export { default as splitEvery } from './splitEvery.js'; | ||
export { default as append } from './append.js'; | ||
export { default as prepend } from './prepend.js'; | ||
export * from './L.js'; | ||
export * from './C.js'; |
import reduce from "./reduce.js"; | ||
import call from "./call.js"; | ||
import go1Sync from "./.internal/go1Sync.js"; | ||
export default function go(..._) { | ||
return reduce(call, _); | ||
return reduce(go1Sync, _); | ||
} |
@@ -1,3 +0,1 @@ | ||
export default function go1(a, f) { | ||
return a instanceof Promise ? a.then(f) : f(a); | ||
} | ||
export default (a, f) => a instanceof Promise ? a.then(f) : f(a); |
import reduceS from "./reduceS.js"; | ||
import call from "./call.js"; | ||
import go1Sync from "./.internal/go1Sync.js"; | ||
export default function goS(..._) { | ||
return reduceS(call, _); | ||
return reduceS(go1Sync, _); | ||
} |
import curry from "./curry.js"; | ||
import reduce from "./reduce.js"; | ||
import go1 from "./go1.js"; | ||
function pushSel(parent, k, v) { | ||
(parent[k] || (parent[k] = [])).push(v); | ||
return parent; | ||
} | ||
export default curry(function groupBy(f, iter) { | ||
return reduce((group, a) => pushSel(group, f(a), a), {}, iter); | ||
return reduce( | ||
(group, a) => go1( | ||
f(a), | ||
k => ((group[k] || (group[k] = [])).push(a), group)), | ||
{}, | ||
iter); | ||
}); |
58
L.js
@@ -7,3 +7,2 @@ import deepFlatLazy from './Lazy/deepFlatLazy.js'; | ||
import flatMapLazy from './Lazy/flatMapLazy.js'; | ||
import headTailLazy from './Lazy/headTailLazy.js'; | ||
import indexValuesLazy from './Lazy/indexValuesLazy.js'; | ||
@@ -21,2 +20,17 @@ import keysLazy from './Lazy/keysLazy.js'; | ||
import dropLazy from "./Lazy/dropLazy.js"; | ||
import differenceLazy from './Lazy/differenceLazy'; | ||
import differenceByLazy from './Lazy/differenceByLazy'; | ||
import intersectionLazy from './Lazy/intersectionLazy'; | ||
import intersectionByLazy from './Lazy/intersectionByLazy'; | ||
import unionByLazy from './Lazy/unionByLazy'; | ||
import unionLazy from './Lazy/unionLazy'; | ||
import dropWhileLazy from './Lazy/dropWhileLazy'; | ||
import dropUntilLazy from './Lazy/dropUntilLazy'; | ||
import compactLazy from "./Lazy/compactLazy.js"; | ||
import chunkLazy from "./Lazy/chunkLazy.js"; | ||
import splitEveryLazy from "./Lazy/splitEveryLazy.js"; | ||
import emptyLazy from "./Lazy/emptyLazy.js"; | ||
import constantLazy from "./Lazy/constantLazy.js"; | ||
import appendLazy from "./Lazy/appendLazy.js"; | ||
import prependLazy from "./Lazy/prependLazy.js"; | ||
@@ -37,3 +51,2 @@ const L = { | ||
flat_map: flatMapLazy, | ||
headTail: headTailLazy, | ||
indexValues: indexValuesLazy, | ||
@@ -53,3 +66,24 @@ index_values: indexValuesLazy, | ||
interval: intervalLazy, | ||
drop: dropLazy | ||
drop: dropLazy, | ||
drop_while: dropWhileLazy, | ||
dropWhile: dropWhileLazy, | ||
drop_until: dropUntilLazy, | ||
dropUntil: dropUntilLazy, | ||
difference: differenceLazy, | ||
differenceBy: differenceByLazy, | ||
difference_by: differenceByLazy, | ||
intersection: intersectionLazy, | ||
intersectionBy: intersectionByLazy, | ||
intersection_by: intersectionByLazy, | ||
union: unionLazy, | ||
union_by: unionByLazy, | ||
unionBy: unionByLazy, | ||
compact: compactLazy, | ||
chunk: chunkLazy, | ||
split_every: splitEveryLazy, | ||
splitEvery: splitEveryLazy, | ||
constant: constantLazy, | ||
empty: emptyLazy, | ||
append: appendLazy, | ||
prepend: prependLazy, | ||
}; | ||
@@ -65,3 +99,2 @@ | ||
flatMapLazy, | ||
headTailLazy, | ||
indexValuesLazy, | ||
@@ -78,3 +111,18 @@ keysLazy, | ||
intervalLazy, | ||
dropLazy | ||
dropLazy, | ||
dropWhileLazy, | ||
dropUntilLazy, | ||
differenceLazy, | ||
differenceByLazy, | ||
intersectionLazy, | ||
intersectionByLazy, | ||
unionByLazy, | ||
unionLazy, | ||
compactLazy, | ||
chunkLazy, | ||
splitEveryLazy, | ||
constantLazy, | ||
emptyLazy, | ||
appendLazy, | ||
prependLazy, | ||
} |
import curry from "../curry.js"; | ||
import safety from "../safety.js"; | ||
import toIter from "../toIter.js"; | ||
import noop from "../noop.js"; | ||
import nop from "../nop.js"; | ||
export default curry(function *dropLazy(l, iter) { | ||
if (l < 1) return yield *safety(iter); | ||
for (const a of safety(iter)) { | ||
if (a instanceof Promise) yield a.then(a => l ? (l--, Promise.reject(nop)) : a); | ||
else if (l) { l--; continue; } | ||
else yield a; | ||
export default curry(function* dropLazy(l, iter) { | ||
if (l < 1) yield* iter; | ||
let prev = null, i = 0; | ||
iter = toIter(iter); | ||
for(const a of iter) { | ||
if (a instanceof Promise) { | ||
a.catch(noop); | ||
yield prev = (prev || Promise.resolve()) | ||
.then(_ => a) | ||
.then(b => ++i > l ? b : Promise.reject(nop)); | ||
prev = prev.catch(noop); | ||
} else if (++i == l) return yield* iter; | ||
} | ||
}); |
@@ -1,3 +0,3 @@ | ||
export default function *entriesLazy(obj) { | ||
export default function* entriesLazy(obj) { | ||
for (const k in obj) yield [k, obj[k]]; | ||
} |
import curry from "../curry.js"; | ||
import go1 from "../go1.js"; | ||
import nop from "../nop.js"; | ||
import safety from "../safety.js"; | ||
import toIter from "../toIter.js"; | ||
export default curry(function *filterLazy(f, iter) { | ||
for (const a of safety(iter)) { | ||
export default curry(function* filterLazy(f, iter) { | ||
for (const a of toIter(iter)) { | ||
const b = go1(a, f); | ||
@@ -9,0 +9,0 @@ if (b instanceof Promise) yield b.then(b => b ? a : Promise.reject(nop)); |
@@ -7,2 +7,3 @@ import isIterable from "../isIterable.js"; | ||
export default function flatLazy(iter, depth = 1) { | ||
let concurCheck = null; | ||
const iterStack = [toIter(iter)]; | ||
@@ -21,7 +22,16 @@ return { | ||
} else if (cur.value instanceof Promise) { | ||
if (concurCheck && !concurCheck.done) { | ||
iterStack.length = 0; | ||
return { value: Promise.reject(new Error("'L.flat' can not be used with 'C' function.")), done: false }; | ||
} | ||
concurCheck = concurCheck || {}; | ||
return { | ||
value: cur.value.then(value => { | ||
if (!concurCheck.hasOwnProperty('done')) concurCheck.done = true; | ||
if (iterStack.length > depth || !isIterable(value) || typeof value == 'string') return value; | ||
const iter = value[Symbol.iterator](), cur = iter.next(); | ||
return cur.done ? Promise.reject(nop) : (iterStack.push(iter), cur.value); | ||
}).catch(e => { | ||
if (!concurCheck.hasOwnProperty('done')) concurCheck.done = true; | ||
return Promise.reject(e); | ||
}), | ||
@@ -28,0 +38,0 @@ done: false |
@@ -1,6 +0,6 @@ | ||
import safety from "../safety.js"; | ||
import toIter from "../toIter.js"; | ||
export default function *indexValuesLazy(iter) { | ||
export default function* indexValuesLazy(iter) { | ||
let i = -1; | ||
for (const a of safety(iter)) yield [++i, a]; | ||
for (const a of toIter(iter)) yield [++i, a]; | ||
}; |
@@ -1,3 +0,3 @@ | ||
export default function *keysLazy(obj) { | ||
export default function* keysLazy(obj) { | ||
for (const k in obj) yield k; | ||
}; |
import curry from "../curry.js"; | ||
import go1 from "../go1.js"; | ||
import safety from "../safety.js"; | ||
import toIter from "../toIter.js"; | ||
export default curry(function *mapEntriesLazy(f, iter) { | ||
for (const [k, a] of safety(iter)) yield go1(go1(a, f), b => [k, b]); | ||
export default curry(function* mapEntriesLazy(f, iter) { | ||
for (const [k, a] of toIter(iter)) yield go1(go1(a, f), b => [k, b]); | ||
}); |
import curry from '../curry.js'; | ||
import go1 from '../go1.js'; | ||
import safety from "../safety.js"; | ||
import toIter from "../toIter.js"; | ||
export default curry(function *mapLazy(f, iter) { | ||
for (const a of safety(iter)) yield go1(a, f); | ||
export default curry(function* mapLazy(f, iter) { | ||
for (const a of toIter(iter)) yield go1(a, f); | ||
}); |
@@ -1,7 +0,16 @@ | ||
export default function *rangeLazy(start = 0, stop = start, step = 1) { | ||
if (arguments.length == 1) start = 0; | ||
while (start < stop) { | ||
yield start; | ||
start += step; | ||
export default function* rangeLazy(start = 0, stop = start, step = 1) { | ||
if (arguments.length === 1) start = 0; | ||
if (arguments.length < 3 && start > stop) step *= -1; | ||
if (start < stop) { | ||
while (start < stop) { | ||
yield start; | ||
start += step; | ||
} | ||
} else { | ||
while (start > stop) { | ||
yield start; | ||
start += step; | ||
} | ||
} | ||
} |
@@ -1,4 +0,4 @@ | ||
export default function *reverseLazy(arr) { | ||
export default function* reverseLazy(arr) { | ||
var l = arr.length; | ||
while (l--) yield arr[l]; | ||
} |
import curry from "../curry.js"; | ||
import safety from "../safety.js"; | ||
import toIter from "../toIter.js"; | ||
import noop from "../noop.js"; | ||
import nop from "../nop.js"; | ||
export default curry(function *takeLazy(l, iter) { | ||
export default curry(function* takeLazy(l, iter) { | ||
if (l < 1) return; | ||
for (const a of safety(iter)) { | ||
if (a instanceof Promise) yield a.then(a => (--l, a)); | ||
else yield (--l, a); | ||
let prev = null; | ||
for (const a of toIter(iter)) { | ||
if (a instanceof Promise) { | ||
a.catch(noop); | ||
yield prev = (prev || Promise.resolve()) | ||
.then(_ => a) | ||
.then(a => --l > -1 ? a : Promise.reject(nop)); | ||
prev = prev.catch(noop); | ||
} else { | ||
yield (--l, a); | ||
} | ||
if (!l) break; | ||
} | ||
}); |
import curry from "../curry.js"; | ||
import go1 from "../go1.js"; | ||
import safety from "../safety.js"; | ||
import toIter from "../toIter.js"; | ||
import noop from "../noop.js"; | ||
import nop from "../nop.js"; | ||
export default curry(function *takeUntilLazy(f, iter) { | ||
let ok = false; | ||
for (const a of safety(iter)) { | ||
ok = go1(a, f); | ||
if (ok instanceof Promise) yield ok.then(_ok => ((ok = _ok), a)); | ||
else yield a; | ||
export default curry(function* takeUntilLazy(f, iter) { | ||
let prev = null, ok = false; | ||
for (const a of toIter(iter)) { | ||
const _ok = ok || go1(a, f); | ||
if (_ok instanceof Promise) { | ||
_ok.catch(noop); | ||
yield prev = (prev || Promise.resolve()) | ||
.then(_ => _ok) | ||
.then(_ok => ok ? Promise.reject(nop) : ((ok = _ok), a)); | ||
prev = prev.catch(noop); | ||
} else { | ||
ok = _ok; | ||
yield a; | ||
} | ||
if (ok) break; | ||
} | ||
}); |
import curry from "../curry.js"; | ||
import nop from "../nop.js"; | ||
import go1 from "../go1.js"; | ||
import safety from "../safety.js"; | ||
import toIter from "../toIter.js"; | ||
import noop from "../noop.js"; | ||
export default curry(function *takeWhileLazy(f, iter) { | ||
let ok = false; | ||
for (const a of safety(iter)) { | ||
ok = go1(a, f); | ||
if (ok instanceof Promise) yield ok.then(_ok => (ok = _ok) ? a : Promise.reject(nop)); | ||
else if (ok) yield a; | ||
const resolved = Promise.resolve(); | ||
export default curry(function* takeWhileLazy(f, iter) { | ||
let prev = resolved, ok = true; | ||
for (const a of toIter(iter)) { | ||
const _ok = ok && go1(a, f); | ||
if (_ok instanceof Promise) { | ||
_ok.catch(noop); | ||
yield prev = prev.then(_ => _ok).then(_ok => (ok = _ok) ? a : Promise.reject(nop)); | ||
prev = prev.catch(noop); | ||
} else if (ok = _ok) { | ||
yield a; | ||
} | ||
if (!ok) break; | ||
} | ||
}); |
@@ -1,3 +0,3 @@ | ||
export default function *valuesLazy(obj) { | ||
export default function* valuesLazy(obj) { | ||
for (const k in obj) yield obj[k]; | ||
} |
import rejectLazy from "./Lazy/rejectLazy.js"; | ||
import curry from "./curry.js"; | ||
import basePick from "./basePick.js"; | ||
import object from "./object.js"; | ||
import entriesLazy from "./Lazy/entriesLazy.js"; | ||
export default curry(function omit(ks, obj) { | ||
return basePick(rejectLazy, ks, obj); | ||
return object( | ||
rejectLazy(([k]) => ks.includes(k), | ||
entriesLazy(obj))); | ||
}); |
{ | ||
"name": "fxjs2", | ||
"version": "0.2.7", | ||
"description": "Functional Extensions for Javascript", | ||
"version": "0.9.0", | ||
"description": "Functional Extensions for modern Javascript", | ||
"main": "index.js", | ||
@@ -9,10 +9,12 @@ "module": "fx.js", | ||
"scripts": { | ||
"build": "npm run build-modern && npm run build-legacy", | ||
"build-modern": "webpack --config modern.config.js --env.NODE_ENV=production", | ||
"build-legacy": "webpack --config legacy.config.js --env.NODE_ENV=production", | ||
"test": "mocha -R spec test/**/*.js" | ||
}, | ||
"files": [ | ||
"Concurrency/*", | ||
"Lazy/*", | ||
"*.js", | ||
"LICENSE", | ||
"README.md" | ||
"Concurrency", | ||
"Lazy", | ||
"dist", | ||
"*.js" | ||
], | ||
@@ -23,3 +25,17 @@ "repository": { | ||
}, | ||
"author": "", | ||
"author": "Indong Yoo <idy@marpple.com>", | ||
"contributors": [ | ||
{ | ||
"name": "Indong Yoo", | ||
"email": "idy@marpple.com" | ||
}, | ||
{ | ||
"name": "Piljung Park", | ||
"email": "pjp@marpple.com" | ||
}, | ||
{ | ||
"name": "Dohyeong Lee", | ||
"email": "dhl@marpple.com" | ||
} | ||
], | ||
"license": "MIT", | ||
@@ -31,8 +47,29 @@ "bugs": { | ||
"dependencies": { | ||
"esm": "^3.0.80" | ||
"core-js": "^3.0.1", | ||
"esm": "^3.0.80", | ||
"regenerator-runtime": "^0.13.2" | ||
}, | ||
"devDependencies": { | ||
"lodash": ">=4.17.13", | ||
"@babel/cli": "^7.4.4", | ||
"@babel/core": "^7.4.4", | ||
"@babel/preset-env": "^7.4.4", | ||
"babel-loader": "^8.0.5", | ||
"chai": "^4.1.2", | ||
"mocha": "^5.2.0" | ||
} | ||
"mocha": "^5.2.0", | ||
"terser-webpack-plugin": "^1.2.3", | ||
"uglifyjs-webpack-plugin": "^2.1.2", | ||
"webpack": "^4.30.0", | ||
"webpack-cli": "^3.3.1" | ||
}, | ||
"directories": { | ||
"test": "test" | ||
}, | ||
"keywords": [ | ||
"functional", | ||
"fp", | ||
"fxjs" | ||
], | ||
"unpkg": "dist/fx.es5.min.js", | ||
"jsdelivr": "dist/fx.es5.min.js" | ||
} |
@@ -1,7 +0,10 @@ | ||
import filterLazy from "./Lazy/filterLazy.js"; | ||
import curry from "./curry.js"; | ||
import basePick from "./basePick.js"; | ||
import object from "./object.js"; | ||
import rejectLazy from "./Lazy/rejectLazy.js"; | ||
import mapLazy from "./Lazy/mapLazy.js"; | ||
export default curry(function pick(ks, obj) { | ||
return basePick(filterLazy, ks, obj); | ||
return object( | ||
rejectLazy(([_, v]) => v === undefined, | ||
mapLazy(k => [k, obj[k]], ks))); | ||
}); |
import reduce from "./reduce.js"; | ||
import call from "./call.js"; | ||
import go1Sync from "./.internal/go1Sync.js"; | ||
export default function pipe(f, ...fs) { | ||
return (...as) => reduce(call, f(...as), fs); | ||
return (...as) => reduce(go1Sync, f(...as), fs); | ||
} |
import reduceS from "./reduceS.js"; | ||
import call from "./call.js"; | ||
import go1Sync from "./.internal/go1Sync.js"; | ||
export default function pipeS(f, ...fs) { | ||
return (...as) => reduceS(call, f(...as), fs); | ||
return (...as) => reduceS(go1Sync, f(...as), fs); | ||
} |
449
README.md
[EN](https://github.com/marpple/FxJS) | [KR](https://github.com/marpple/FxJS/blob/master/README_kr.md) | ||
## FxJS - Functional Extensions for Javascript | ||
# FxJS - Functional Extensions for Javascript | ||
FxJS is a functional programming library that uses basic JavaScript values and emphasizes repeatable programming and Promise. | ||
FxJS is a functional programming library based on ECMAScript 6. Iterable, Iterator, Generator, Promise. | ||
### iterable | ||
- [Getting Started](#getting-started) | ||
- [Installation](#Installation) | ||
- [Iteration protocols](#Iteration-protocols) | ||
- [Iterable programming](#Iterable-programming) | ||
- [Lazy evaluation](#Lazy-evaluation) | ||
- [RFP style](#RFP-style) | ||
- [Promise/async/await](#promiseasyncawait) | ||
- [Concurrency](#Concurrency) | ||
- [Error handling](#Error-handling) | ||
- [API](https://github.com/marpple/FxJS/blob/master/API.md#API) | ||
- [Function](https://github.com/marpple/FxJS/blob/master/API.md#Function) | ||
- [Strict](https://github.com/marpple/FxJS/blob/master/API.md#strict) | ||
- [Predicates](https://github.com/marpple/FxJS/blob/master/API.md#Predicates) | ||
- [Lazy](https://github.com/marpple/FxJS/blob/master/API.md#lazy) | ||
- [Concurrency](https://github.com/marpple/FxJS/blob/master/API.md#concurrency) | ||
- [Stoppable](https://github.com/marpple/FxJS/blob/master/API.md#stoppable) | ||
- [String](https://github.com/marpple/FxJS/blob/master/API.md#String) | ||
- [Change Log](#Change-Log) | ||
```javascript | ||
const res = go( | ||
L.range(Infinity), | ||
L.filter(a => a % 2), | ||
L.take(3), | ||
reduce(add)); | ||
# Getting Started | ||
log(res); // 9 | ||
## Installation | ||
### In Modern Browsers Supporting ES6 | ||
- [fx.js](https://github.com/marpple/FxJS/blob/master/dist/fx.js) | ||
- [fx.js.map](https://github.com/marpple/FxJS/blob/master/dist/fx.js.map) | ||
- [fx.min.js](https://github.com/marpple/FxJS/blob/master/dist/fx.min.js) | ||
```html | ||
<script src="path/fx.min.js"></script> | ||
``` | ||
### iterable + time | ||
### In Legacy ES5 Browsers | ||
- [fx.es5.js](https://github.com/marpple/FxJS/blob/master/dist/fx.es5.js) | ||
- [fx.es5.js.map](https://github.com/marpple/FxJS/blob/master/dist/fx.es5.js.map) | ||
- [fx.es5.min.js](https://github.com/marpple/FxJS/blob/master/dist/fx.es5.min.js) | ||
```html | ||
<script src="path/fx.es5.min.js"></script> | ||
``` | ||
### In Node.js | ||
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 | ||
``` | ||
```javascript | ||
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 | ||
import { map, filter, reduce, L, C } from "fxjs2"; | ||
``` | ||
### iterable + time + Promise | ||
We use [esm](https://github.com/standard-things/esm) to import the FxJS functions created in the ECMAScript Module into the CommonJS Module. | ||
```javascrip | ||
const { map, filter, reduce, L, C } = require("fxjs2"); | ||
``` | ||
## Iteration protocols | ||
You can evaluate the iterator as a function of FxJS. | ||
```javascript | ||
// L.interval = time => L.map(delay(time), L.range(Infinity)); | ||
function *fibonacci() { | ||
let a = 0, b = 1; | ||
while (true) { | ||
yield a; | ||
[a, b] = [b, a + b]; | ||
} | ||
} | ||
(async () => { | ||
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 f = pipe( | ||
fibonacci, | ||
L.filter(n => n % 2 == 0), | ||
L.takeWhile(n => n < 10)); | ||
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 | ||
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 } | ||
log(res); | ||
// 63 | ||
} ()); | ||
reduce((a, b) => a + b, f()); | ||
// 10 | ||
``` | ||
### Install | ||
## Iterable programming | ||
Any value can be used with FxJS if it has a `[Symbol.iterator]()` method. | ||
```javascript | ||
const res = go( | ||
[1, 2, 3, 4, 5], | ||
filter(a => a % 2), | ||
reduce(add)); | ||
log(res); // 9 | ||
``` | ||
npm i fxjs2 | ||
``` | ||
### API | ||
## Lazy evaluation | ||
- [map](#map) | ||
- [filter](#filter) | ||
- [reduce](#reduce) | ||
- [take](#take) | ||
- [L.map](#L.map) | ||
- [L.filter](#L.filter) | ||
- [go + try catch + Asynchronous error handling](#go--try-catch--Asynchronous-error-handling) | ||
- [stop](#stop) | ||
You can do 'lazy evaluation' as a function of the `L` namespace. | ||
#### map | ||
```javascript | ||
const res = go( | ||
L.range(Infinity), | ||
L.filter(a => a % 2), | ||
L.take(3), | ||
reduce(add)); | ||
```javascript | ||
map(a => a + 10, [1, 2, 3]); | ||
// [11, 12, 13] | ||
log(res); // 9 | ||
``` | ||
#### filter | ||
## RFP style | ||
Reactive functional programming style. | ||
```javascript | ||
filter(a => a % 2, [1, 2, 3]); | ||
// [1, 3] | ||
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 | ||
``` | ||
#### reduce | ||
## Promise/async/await | ||
Asynchronous control is easy. | ||
```javascript | ||
const add = (a, b) => a + b | ||
reduce(add, [1, 2, 3]); | ||
// 6 | ||
// L.interval = time => L.map(delay(time), L.range(Infinity)); | ||
reduce(add, 10, [1, 2, 3]); | ||
// 16 | ||
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 | ||
reduce(add, {a: 1, b: 2, c: 3}); | ||
// 6 | ||
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 | ||
await reduce(add, [Promise.resolve(1), 2, 3]) | ||
// 6 | ||
log(res); | ||
// 63 | ||
``` | ||
#### take | ||
## Concurrency | ||
`C` functions can be evaluated concurrency. | ||
```javascript | ||
take(1, [1, 2, 3]); | ||
// [1] | ||
await map(getPage, range(1, 5)); | ||
// After 4 seconds | ||
// [page1, page2, page3, page4] | ||
take(2, [1, 2, 3]) | ||
// [1, 2] | ||
const pages = await C.map(getPage, range(1, 5)); | ||
// After 1 second | ||
// [page1, page2, page3, page4] | ||
``` | ||
#### L.map | ||
Like [Clojure Reducers](https://clojure.org/reference/reducers), you can handle concurrency. | ||
```javascript | ||
const iterator = L.map(a => a + 10, [1, 2, 3]); | ||
take(2, iterator); | ||
// [11, 12] | ||
``` | ||
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 ... } | ||
#### L.filter | ||
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 ... } | ||
```javascript | ||
const iterator = L.filter(a => a % 2, [1, 2, 3, 4, 5]); | ||
take(2, iterator); | ||
// [1, 3] | ||
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 ... } | ||
``` | ||
```javascript | ||
const iterator = L.filter(a => a % 2, L.map(a => a + 10, [1, 2, 3, 4, 5])); | ||
take(2, iterator); | ||
// [11, 13] | ||
``` | ||
## Error handling | ||
#### go + try catch + Asynchronous error handling | ||
You can use JavaScript standard error handling. | ||
@@ -168,3 +248,7 @@ ```javascript | ||
// { hi: 'ho' } | ||
``` | ||
You can use async/await and try/catch to handle asynchronous error handling. | ||
```javascript | ||
const b = await go( | ||
@@ -191,38 +275,149 @@ 0, | ||
// { 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' } | ||
``` | ||
### stop | ||
# API | ||
```javascript | ||
const f1 = pipeS( | ||
a => a % 2 ? stop(a) : a, | ||
a => a + 10); | ||
f1(1); // 1 | ||
f1(2); // 12 | ||
- [Function](https://github.com/marpple/FxJS/blob/master/API.md#Function) | ||
- [go](https://github.com/marpple/FxJS/blob/master/API.md#go) | ||
- [pipe](https://github.com/marpple/FxJS/blob/master/API.md#pipe) | ||
- [curry](https://github.com/marpple/FxJS/blob/master/API.md#curry) | ||
- [tap](https://github.com/marpple/FxJS/blob/master/API.md#tap) | ||
- [constant](https://github.com/marpple/FxJS/blob/master/API.md#constant) | ||
- [negate](https://github.com/marpple/FxJS/blob/master/API.md#negate) | ||
- [call](https://github.com/marpple/FxJS/blob/master/API.md#call) | ||
- [apply](https://github.com/marpple/FxJS/blob/master/API.md#apply) | ||
- [calls](https://github.com/marpple/FxJS/blob/master/API.md#calls) | ||
- [throttle](https://github.com/marpple/FxJS/blob/master/API.md#throttle) | ||
- [debounce](https://github.com/marpple/FxJS/blob/master/API.md#debounce) | ||
- [Strict](https://github.com/marpple/FxJS/blob/master/API.md#strict) | ||
- [range](https://github.com/marpple/FxJS/blob/master/API.md#range) | ||
- [map](https://github.com/marpple/FxJS/blob/master/API.md#map) | ||
- [mapEntries](https://github.com/marpple/FxJS/blob/master/API.md#mapEntries) | ||
- [mapObject](https://github.com/marpple/FxJS/blob/master/API.md#mapObject) | ||
- [pluck](https://github.com/marpple/FxJS/blob/master/API.md#pluck) | ||
- [flat](https://github.com/marpple/FxJS/blob/master/API.md#flat) | ||
- [deepFlat](https://github.com/marpple/FxJS/blob/master/API.md#deepFlat) | ||
- [flatMap](https://github.com/marpple/FxJS/blob/master/API.md#flatMap) | ||
- [filter](https://github.com/marpple/FxJS/blob/master/API.md#filter) | ||
- [reject](https://github.com/marpple/FxJS/blob/master/API.md#reject) | ||
- [compact](https://github.com/marpple/FxJS/blob/master/API.md#compact) | ||
- [unique](https://github.com/marpple/FxJS/blob/master/API.md#unique) | ||
- [difference](https://github.com/marpple/FxJS/blob/master/API.md#difference) | ||
- [differenceBy](https://github.com/marpple/FxJS/blob/master/API.md#differenceBy) | ||
- [intersection](https://github.com/marpple/FxJS/blob/master/API.md#intersection) | ||
- [intersectionBy](https://github.com/marpple/FxJS/blob/master/API.md#intersectionBy) | ||
- [union](https://github.com/marpple/FxJS/blob/master/API.md#union) | ||
- [unionBy](https://github.com/marpple/FxJS/blob/master/API.md#unionBy) | ||
- [reduce](https://github.com/marpple/FxJS/blob/master/API.md#reduce) | ||
- [each](https://github.com/marpple/FxJS/blob/master/API.md#each) | ||
- [partition](https://github.com/marpple/FxJS/blob/master/API.md#partition) | ||
- [countBy](https://github.com/marpple/FxJS/blob/master/API.md#countBy) | ||
- [groupBy](https://github.com/marpple/FxJS/blob/master/API.md#groupBy) | ||
- [indexBy](https://github.com/marpple/FxJS/blob/master/API.md#indexBy) | ||
- [max](https://github.com/marpple/FxJS/blob/master/API.md#max) | ||
- [maxBy](https://github.com/marpple/FxJS/blob/master/API.md#maxBy) | ||
- [min](https://github.com/marpple/FxJS/blob/master/API.md#min) | ||
- [minBy](https://github.com/marpple/FxJS/blob/master/API.md#minBy) | ||
- [sort](https://github.com/marpple/FxJS/blob/master/API.md#sort) | ||
- [sortBy](https://github.com/marpple/FxJS/blob/master/API.md#sortBy) | ||
- [sortDesc](https://github.com/marpple/FxJS/blob/master/API.md#sortDesc) | ||
- [sortByDesc](https://github.com/marpple/FxJS/blob/master/API.md#sortByDesc) | ||
- [object](https://github.com/marpple/FxJS/blob/master/API.md#object) | ||
- [pick](https://github.com/marpple/FxJS/blob/master/API.md#pick) | ||
- [omit](https://github.com/marpple/FxJS/blob/master/API.md#omit) | ||
- [values](https://github.com/marpple/FxJS/blob/master/API.md#values) | ||
- [keys](https://github.com/marpple/FxJS/blob/master/API.md#keys) | ||
- [entries](https://github.com/marpple/FxJS/blob/master/API.md#entries) | ||
- [extend](https://github.com/marpple/FxJS/blob/master/API.md#extend) | ||
- [defaults](https://github.com/marpple/FxJS/blob/master/API.md#defaults) | ||
- [baseSel](https://github.com/marpple/FxJS/blob/master/API.md#baseSel) | ||
- [sel](https://github.com/marpple/FxJS/blob/master/API.md#sel) | ||
- [take](https://github.com/marpple/FxJS/blob/master/API.md#take) | ||
- [takeWhile](https://github.com/marpple/FxJS/blob/master/API.md#takeWhile) | ||
- [takeUntil](https://github.com/marpple/FxJS/blob/master/API.md#takeUntil) | ||
- [takeAll](https://github.com/marpple/FxJS/blob/master/API.md#takeAll) | ||
- [drop](https://github.com/marpple/FxJS/blob/master/API.md#drop) | ||
- [dropWhile](https://github.com/marpple/FxJS/blob/master/API.md#dropWhile) | ||
- [dropUntil](https://github.com/marpple/FxJS/blob/master/API.md#dropUntil) | ||
- [dropRight](https://github.com/marpple/FxJS/blob/master/API.md#dropRight) | ||
- [head](https://github.com/marpple/FxJS/blob/master/API.md#head) | ||
- [tail](https://github.com/marpple/FxJS/blob/master/API.md#tail) | ||
- [last](https://github.com/marpple/FxJS/blob/master/API.md#last) | ||
- [initial](https://github.com/marpple/FxJS/blob/master/API.md#initial) | ||
- [find](https://github.com/marpple/FxJS/blob/master/API.md#find) | ||
- [findWhere](https://github.com/marpple/FxJS/blob/master/API.md#findWhere) | ||
- [zip](https://github.com/marpple/FxJS/blob/master/API.md#zip) | ||
- [unzip](https://github.com/marpple/FxJS/blob/master/API.md#unzip) | ||
- [zipObj](https://github.com/marpple/FxJS/blob/master/API.md#zipObj) | ||
- [zipWith](https://github.com/marpple/FxJS/blob/master/API.md#zipWith) | ||
- [delay](https://github.com/marpple/FxJS/blob/master/API.md#delay) | ||
- [promiseAllObject](https://github.com/marpple/FxJS/blob/master/API.md#promiseAllObject) | ||
- [promiseAllEntries](https://github.com/marpple/FxJS/blob/master/API.md#promiseAllEntries) | ||
- [noop](https://github.com/marpple/FxJS/blob/master/API.md#noop) | ||
- [identity](https://github.com/marpple/FxJS/blob/master/API.md#identity) | ||
- [Predicates](https://github.com/marpple/FxJS/blob/master/API.md#Predicates) | ||
- [some](https://github.com/marpple/FxJS/blob/master/API.md#some) | ||
- [every](https://github.com/marpple/FxJS/blob/master/API.md#every) | ||
- [match](https://github.com/marpple/FxJS/blob/master/API.md#match) | ||
- [isMatch](https://github.com/marpple/FxJS/blob/master/API.md#isMatch) | ||
- [isIterable](https://github.com/marpple/FxJS/blob/master/API.md#isIterable) | ||
- [isFunction](https://github.com/marpple/FxJS/blob/master/API.md#isFunction) | ||
- [isArray](https://github.com/marpple/FxJS/blob/master/API.md#isArray) | ||
- [isString](https://github.com/marpple/FxJS/blob/master/API.md#isString) | ||
- [isUndefined](https://github.com/marpple/FxJS/blob/master/API.md#isUndefined) | ||
- [Lazy](https://github.com/marpple/FxJS/blob/master/API.md#lazy) | ||
- [L.range](https://github.com/marpple/FxJS/blob/master/API.md#lrange) | ||
- [L.map](https://github.com/marpple/FxJS/blob/master/API.md#lmap) | ||
- [L.filter](https://github.com/marpple/FxJS/blob/master/API.md#lfilter) | ||
- [L.reject](https://github.com/marpple/FxJS/blob/master/API.md#lreject) | ||
- [L.compact](https://github.com/marpple/FxJS/blob/master/API.md#lcompact) | ||
- [L.mapEntries](https://github.com/marpple/FxJS/blob/master/API.md#lmapEntries) | ||
- [L.entries](https://github.com/marpple/FxJS/blob/master/API.md#lentries) | ||
- [L.values](https://github.com/marpple/FxJS/blob/master/API.md#lvalues) | ||
- [L.keys](https://github.com/marpple/FxJS/blob/master/API.md#lkeys) | ||
- [L.indexValues](https://github.com/marpple/FxJS/blob/master/API.md#lindexValues) | ||
- [L.flat](https://github.com/marpple/FxJS/blob/master/API.md#lflat) | ||
- [L.flatMap](https://github.com/marpple/FxJS/blob/master/API.md#lflatMap) | ||
- [L.deepFlat](https://github.com/marpple/FxJS/blob/master/API.md#ldeepFlat) | ||
- [L.reverse](https://github.com/marpple/FxJS/blob/master/API.md#lreverse) | ||
- [L.take](https://github.com/marpple/FxJS/blob/master/API.md#ltake) | ||
- [L.takeWhile](https://github.com/marpple/FxJS/blob/master/API.md#ltakeWhile) | ||
- [L.takeUntil](https://github.com/marpple/FxJS/blob/master/API.md#ltakeUntil) | ||
- [L.drop](https://github.com/marpple/FxJS/blob/master/API.md#ldrop) | ||
- [L.dropWhile](https://github.com/marpple/FxJS/blob/master/API.md#ldropWhile) | ||
- [L.dropUntil](https://github.com/marpple/FxJS/blob/master/API.md#ldropUntil) | ||
- [L.difference](https://github.com/marpple/FxJS/blob/master/API.md#ldifference) | ||
- [L.differenceBy](https://github.com/marpple/FxJS/blob/master/API.md#ldifferenceBy) | ||
- [L.intersection](https://github.com/marpple/FxJS/blob/master/API.md#lintersection) | ||
- [L.intersectionBy](https://github.com/marpple/FxJS/blob/master/API.md#lintersectionBy) | ||
- [L.union](https://github.com/marpple/FxJS/blob/master/API.md#lunion) | ||
- [L.unionBy](https://github.com/marpple/FxJS/blob/master/API.md#lunionBy) | ||
- [L.interval](https://github.com/marpple/FxJS/blob/master/API.md#linterval) | ||
- [Concurrency](https://github.com/marpple/FxJS/blob/master/API.md#concurrency) | ||
- [C.calls](https://github.com/marpple/FxJS/blob/master/API.md#ccalls) | ||
- [C.takeAll](https://github.com/marpple/FxJS/blob/master/API.md#ctakeAll) | ||
- [C.takeRace](https://github.com/marpple/FxJS/blob/master/API.md#ctakeRace) | ||
- [C.race](https://github.com/marpple/FxJS/blob/master/API.md#crace) | ||
- [C.map](https://github.com/marpple/FxJS/blob/master/API.md#cmap) | ||
- [C.mapEntries](https://github.com/marpple/FxJS/blob/master/API.md#cmapEntries) | ||
- [C.filter](https://github.com/marpple/FxJS/blob/master/API.md#cfilter) | ||
- [C.compact](https://github.com/marpple/FxJS/blob/master/API.md#ccompact) | ||
- [C.reduce](https://github.com/marpple/FxJS/blob/master/API.md#creduce) | ||
- [C.take](https://github.com/marpple/FxJS/blob/master/API.md#ctake) | ||
- [C.drop](https://github.com/marpple/FxJS/blob/master/API.md#cdrop) | ||
- [C.take1](https://github.com/marpple/FxJS/blob/master/API.md#ctake1) | ||
- [C.head](https://github.com/marpple/FxJS/blob/master/API.md#chead) | ||
- [C.tail](https://github.com/marpple/FxJS/blob/master/API.md#ctail) | ||
- [C.find](https://github.com/marpple/FxJS/blob/master/API.md#cfind) | ||
- [C.every](https://github.com/marpple/FxJS/blob/master/API.md#cevery) | ||
- [C.some](https://github.com/marpple/FxJS/blob/master/API.md#csome) | ||
- [Stoppable](https://github.com/marpple/FxJS/blob/master/API.md#stoppable) | ||
- [reduceS, stop](https://github.com/marpple/FxJS/blob/master/API.md#reduces-stop) | ||
- [goS, pipeS, stop, stopIf](https://github.com/marpple/FxJS/blob/master/API.md#gos-pipes-stop-stopif) | ||
- [String](https://github.com/marpple/FxJS/blob/master/API.md#String) | ||
- [string](https://github.com/marpple/FxJS/blob/master/API.md#string) | ||
- [strMap](https://github.com/marpple/FxJS/blob/master/API.md#strMap) | ||
- [join](https://github.com/marpple/FxJS/blob/master/API.md#join) | ||
- [html](https://github.com/marpple/FxJS/blob/master/API.md#html) | ||
goS({a: 1, b: 2}, | ||
stopIf({a: 1}), | ||
({a, b}) => ({a: a + 10, b})); // {a: 1, b: 2} | ||
goS({a: 2, b: 2}, | ||
stopIf({a: 1}), | ||
({a, b}) => ({a: a + 10, b})); // {a: 12, b: 2} | ||
goS({a: 1, b: 2}, | ||
stopIf({a: 1}, null), | ||
({a, b}) => ({a: a + 10, b})); | ||
// null | ||
``` | ||
# Change Log |
import toIter from "./toIter.js"; | ||
import nop from "./nop.js"; | ||
import go1 from "./go1.js"; | ||
import go2 from "./.internal/go2.js"; | ||
import head from "./head.js"; | ||
const call2 = (acc, a, f) => | ||
a instanceof Promise ? | ||
a.then(a => f(acc, a), e => e == nop ? acc : Promise.reject(e)) : | ||
f(acc, a); | ||
export default function reduce(f, acc, iter) { | ||
@@ -19,3 +14,3 @@ if (arguments.length == 1) return (..._) => reduce(f, ..._); | ||
while (!(cur = iter.next()).done) { | ||
acc = call2(acc, cur.value, f); | ||
acc = go2(acc, cur.value, f); | ||
if (acc instanceof Promise) return acc.then(recur); | ||
@@ -22,0 +17,0 @@ } |
@@ -0,12 +1,7 @@ | ||
import go2 from "./.internal/go2.js"; | ||
import go1 from "./go1.js"; | ||
import toIter from "./toIter.js"; | ||
import nop from "./nop.js"; | ||
import go1 from "./go1.js"; | ||
import head from "./head.js"; | ||
import isStop from "./isStop.js"; | ||
const call2 = (acc, a, f) => | ||
a instanceof Promise ? | ||
a.then(a => f(acc, a), e => e == nop ? acc : Promise.reject(e)) : | ||
f(acc, a); | ||
export default function reduceS(f, acc, iter) { | ||
@@ -20,3 +15,3 @@ if (arguments.length == 1) return (..._) => reduceS(f, ..._); | ||
while (!isStop(acc) && !(cur = iter.next()).done) { | ||
acc = call2(acc, cur.value, f); | ||
acc = go2(acc, cur.value, f); | ||
if (acc instanceof Promise) return acc.then(recur); | ||
@@ -23,0 +18,0 @@ } |
14
some.js
@@ -1,8 +0,14 @@ | ||
import filterLazy from "./Lazy/filterLazy.js"; | ||
import take1 from "./take1.js"; | ||
import go1 from "./go1.js"; | ||
import curry from "./curry.js"; | ||
import go from "./go.js"; | ||
import { mapLazy, takeUntilLazy } from "./L.js"; | ||
import identity from "./identity.js"; | ||
import reduce from "./reduce.js"; | ||
export default curry(function some(f, iter) { | ||
return go1(take1(filterLazy(f, iter)), ({length}) => length == 1); | ||
return go( | ||
mapLazy(f, iter), | ||
takeUntilLazy(identity), | ||
reduce((a, b) => a || b), | ||
(a = false) => a, | ||
Boolean); | ||
}); |
@@ -1,2 +0,2 @@ | ||
import baseSortBy from "./baseSortBy.js"; | ||
import baseSortBy from "./.internal/baseSortBy.js"; | ||
import curry from "./curry.js"; | ||
@@ -3,0 +3,0 @@ |
@@ -1,2 +0,2 @@ | ||
import baseSortBy from "./baseSortBy.js"; | ||
import baseSortBy from "./.internal/baseSortBy.js"; | ||
import curry from "./curry.js"; | ||
@@ -3,0 +3,0 @@ |
@@ -6,3 +6,3 @@ import toIter from "./toIter.js"; | ||
export const takeUntil = curry(function takeUntil(f, iter) { | ||
export default curry(function takeUntil(f, iter) { | ||
let res = []; | ||
@@ -21,4 +21,2 @@ iter = toIter(iter); | ||
} (); | ||
}); | ||
export default takeUntil; | ||
}); |
import reduce from "./reduce.js"; | ||
import call from "./call.js"; | ||
import go1Sync from "./.internal/go1Sync.js"; | ||
import go1 from "./go1.js"; | ||
export default function tap(f, ...fs) { | ||
return (a, ...as) => go1(reduce(call, f(a, ...as), fs), _ => a); | ||
return (a, ...as) => go1(reduce(go1Sync, f(a, ...as), fs), _ => a); | ||
} |
@@ -1,5 +0,5 @@ | ||
import empty from "./empty.js"; | ||
import emptyLazy from "./Lazy/emptyLazy.js"; | ||
export default function toIter(iterable) { | ||
return iterable && iterable[Symbol.iterator] ? iterable[Symbol.iterator]() : empty; | ||
return iterable && iterable[Symbol.iterator] ? iterable[Symbol.iterator]() : emptyLazy(); | ||
} |
@@ -0,5 +1,6 @@ | ||
import identity from './identity.js'; | ||
import uniqueBy from "./uniqueBy.js"; | ||
export default function unique(iter) { | ||
return uniqueBy(a => a, iter); | ||
export default function unique(a) { | ||
return uniqueBy(identity, a); | ||
} |
@@ -1,25 +0,13 @@ | ||
import curry from "./curry.js"; | ||
import isIterable from "./isIterable.js"; | ||
import go from "./go.js"; | ||
import identity from "./identity.js"; | ||
import last from "./last.js"; | ||
import pipe from "./pipe.js"; | ||
import filter from "./Lazy/filterLazy.js"; | ||
import entries from "./Lazy/entriesLazy.js"; | ||
import uniqueByLazy from "./Lazy/uniqueByLazy.js"; | ||
import entriesLazy from './Lazy/entriesLazy.js'; | ||
import curry from './curry.js'; | ||
import isIterable from './isIterable.js'; | ||
import object from './object.js'; | ||
import takeAll from "./takeAll.js"; | ||
import object from "./object.js"; | ||
import last from './last.js'; | ||
export const uniqueBy = curry(function uniqueBy(f, iter) { | ||
const s = new Set(); | ||
const isObj = !isIterable(iter); | ||
return go( | ||
iter, | ||
isObj ? entries : identity, | ||
filter(pipe( | ||
isObj ? last : identity, | ||
f, | ||
b => s.has(b) ? false : s.add(b))), | ||
isObj ? object : takeAll); | ||
}); | ||
export default uniqueBy; | ||
export default curry(function uniqueBy(f, iter) { | ||
return isIterable(iter) ? | ||
takeAll(uniqueByLazy(f, iter)) : | ||
object(uniqueByLazy(e => f(last(e)), entriesLazy(iter))); | ||
}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No contributors or author data
MaintenancePackage does not specify a list of contributors or an author in package.json.
Found 1 instance in 1 package
898685
59
189
9964
0
421
3
11
2
+ Addedcore-js@^3.0.1
+ Addedregenerator-runtime@^0.13.2
+ Addedcore-js@3.39.0(transitive)
+ Addedregenerator-runtime@0.13.11(transitive)