constantiner / fun-ctional Goto Github PK
View Code? Open in Web Editor NEWThe library brings most of the familiar functional techniques (like functional composition) to asynchronous world with shining Promises
License: MIT License
The library brings most of the familiar functional techniques (like functional composition) to asynchronous world with shining Promises
License: MIT License
Add async version of tap
function to handle side effects.
It is like identity
function but has a function as argument.
const log = data => console.log(data);
const someData = "123";
const someDataPromise = Promise.resolve(someData);
atap(log)(someDataPromise).then(resultingData => expect(resultingData).toBeEqual(someData));
It prints 123
in console.
Maybe it will be better to have better types support with TypeScript.
Use @date
tag.
See more details here.
More details here.
Based on sourcemap-validator
.
Extract prettier configuration in separate files
Revise lint rules (consider add unicorn)
Revise husky and lint-staged rules
Add async version of identity
function:
const data = "123";
const dataPromise = Promise.resolve(data);
aidentity(dataPromise).then(resultingData => expect(resultingData).toBeEqual(data));
It is not good to have it in gulpfile.js
. For UMD build it is better to meet best practices.
Remove return
statement here:
fun-ctional/src/util/afilterGeneric.js
Line 22 in 8dfb241
Consider something like VuePress for generation of documentation. See usage example on eslint-utils
project.
Update dependencies etc.
Details are here:
If a function may not return with a value, it might be a good idea to wrap it in an Either. In functional programming, the Either monad is a special abstract data type that allows you to attach two different code paths: a success path, or a fail path. JavaScript has a built-in asynchronous Either monad-ish data type called Promise. You can use it to do declarative error branching for undefined values:
const exists = x => x != null;
const ifExists = value => exists(value) ?
Promise.resolve(value) :
Promise.reject(`Invalid value: ${ value }`);
ifExists(null).then(log).catch(log); // Invalid value: null
ifExists('hello').then(log).catch(log); // hello
You could write a synchronous version of that if you want, but I haven’t needed it much. I’ll leave that as an exercise for you. If you have a good grounding in functors and monads, the process will be easier. If that sounds intimidating, don’t worry about it. Just use promises. They’re built-in and they work fine most of the time.
With current structure of distributive (dist
and esm
folders) it is impossible to import, for example, acompose
separately without using of dist
in import path. Because of f*cking Node module structure reads files in relative to project root but not to main file. So we need to make distribution flat again with mjs
files for ES6 modules.
Leave browser
folder untouched.
Generate them from corresponding JSDoc files. See #17
See sample config here.
It is very unpredictable how IDEs and bundlers work with, for example, mjs
files when use ES6 modules. But placing ES6 files and CJS ones in esm
and cjs
folders with js
extension correspondingly is not the option as far as it requires esm
or cjs
presence when import separate utilities. And placing them together in package root is not the option because of files have the same names.
So I suggest the following:
package.json
's main
field.index.js
of ES6 build in esm
folder and don't produce separate utilities files at all because of ES6 modules are very good in tree shaking and code will use CJS files for separate modules import. Refer this ES6 main module in module
section of package.json
.Both for sources and distributive. Don't forget about package.json
.
Now fun-ctional
API allows to pass functions to acompose
, apipe
and applyFns
both as arguments:
acompose(func1, func2, func3);
and list (as Iterable
):
acompose([func1, func2, func3]);
This Iterable
API is redundant. Let's remove it. If someone for some reason has functions as a list, he/she can apply it this way:
acompose(...[func1, func2, func3]);
Create cjs
folder for CommonJS build files and use these files in main
section of package.json
. Create esm
folder for ES6 modules and use module
section of package.json
for them. Create browser
folder with UMD build for browser of the whole library along with minified version of distribution (and source maps of course).
So we build the whole bundle and separate utilities for CJS and ESM and only the whole bundle for UMD.
See example here.
It is a good idea to launch tests in watch mode in process of development to have faster feedback.
Use GitHub Changelog Generator for that.
Now it adds too much code with tree shaking while using afilter
.
Replace it across all the code. It is more convenient to control them that way.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.