GithubHelp home page GithubHelp logo

constantiner / fun-ctional Goto Github PK

View Code? Open in Web Editor NEW
3.0 3.0 0.0 877 KB

The library brings most of the familiar functional techniques (like functional composition) to asynchronous world with shining Promises

License: MIT License

JavaScript 100.00%
async asynchronous asynchronous-functions asynchronous-programming client-side functional functional-composition functional-programming javascript javascript-library library mapreduce nodejs promise promise-handling promises server-side

fun-ctional's Introduction

Greetings! I'm Konstantin Kovalev aka Constantiner 🧙‍♂️

Welcome to my realm of coding magic and gaming quests:

  • 🛠️ Code Alchemist: I mix TypeScript, React, Next.js and Node.js to conjure up robust web applications. Coding isn’t just my job; it’s my spellcraft!
  • 🧩 Puzzle Solver: From debugging to full-stack development, I love untangling complex code puzzles.
  • 🎮 Dungeon Master: Not just a coder—I'm a master of Nintendo games, always ready for a Mario Kart duel.
  • 🚀 Innovation Explorer: Experimenting with new tech through pet projects, I’m constantly on a quest for the latest and greatest.
  • 🌐 Remote Sorcerer: With a decade of remote work, I've perfected my spells for seamless online collaboration.

Questing for New Adventures: I'm open to joining a new guild where my coding magic can make a difference. Check out my resume for more.

Summon Me: Reach me via [email protected] or connect on LinkedIn.

fun-ctional's People

Contributors

constantiner avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar

fun-ctional's Issues

Asynchronous Either with Promises

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.

Add atap function

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.

Refactor distribution files output

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.

Add aidentity function

Add async version of identity function:

const data = "123";
const dataPromise = Promise.resolve(data);
aidentity(dataPromise).then(resultingData => expect(resultingData).toBeEqual(data));

Optimise distributive for ES6 and CJS modules

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:

  • Place all CJS files in package root and refer to CJS main fale in package.json's main field.
  • Place only main 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.
  • Browser build is without changes.

Fix import of particular utilities

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.

Simplify acompose, apipe and applyFns to only accept functions as arguments

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]);

Improve project configuration

  • Extract prettier configuration in separate files

  • Revise lint rules (consider add unicorn)

  • Revise husky and lint-staged rules

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.