Giter Club home page Giter Club 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

Hi there, I'm Konstantin Kovalev aka Constantiner ๐Ÿ‘‹

Some facts about me:

  • ๐ŸŒฑ I am skilled in TypeScript/JavaScript and love to code servers and clients. I am always on the lookout for the next big tech.
  • ๐Ÿ‘ฏ Adventure enthusiast, whether it's a new challenge or a round of gaming. Speaking of which, want to see my treasure trove of Nintendo games and consoles? ๐ŸŽฎ
  • ๐Ÿ”ญ I'm crafting a technical blog from scratch, harnessing the power of React, TypeScript, Next.js, Tailwind, Prisma, PostgreSQL. It's my playground for exploring cutting-edge technologies.
  • ๐Ÿ“ซ How to reach me: Email me at [email protected] or connect with me on LinkedIn.
  • ๐Ÿ˜„ Pronouns: He/Him
  • โšก Fun fact: I can probably beat you at Mario Kart! ๐ŸŽ๏ธ

By the way, I'm seriously thinking about some new steps in my career journey, so some more facts on that topic:

  • ๐Ÿ” Currently on a quest to find my next exciting adventure in the realm of web development! Need a full-stack developer who thrives on innovation and loves a good challenge? You've found your party member.
  • ๐Ÿ“œ For a detailed account of my epic journey so far, check out my resume.
  • ๐Ÿ’Œ Got a quest you think I might be interested in? I'm all ears! I promise I'm much friendlier than a Level 99 Boss in Shin Megami Tensei! ๐Ÿ˜„

fun-ctional's People

Contributors

constantiner avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar

fun-ctional's Issues

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

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

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.

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.

Improve project configuration

  • Extract prettier configuration in separate files

  • Revise lint rules (consider add unicorn)

  • Revise husky and lint-staged rules

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.

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.

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.