1.4.13 • Published 5 years ago

unlimited-curry v1.4.13

Weekly downloads
3
License
MIT
Repository
github
Last release
5 years ago

Depreceated, from now on please use: dsl-framework

QA monorepo

JavaScript Style Guide

Installation

npm install unlimited-curry --save

Motivation

I wanted to have a small unlimited currying solution for functional programming techniques so that I can develop domain-specific languages easily and keep its application close to the code, Moreover, use it for different kind of tasks. I started educating myself to LISP and tying to transpiring back to my daily work life some practical concept, using data as code and creating small domain specific languages, this is an attempt for that.

I wrote cowlog and the central point of the application is the usage of its specific small DSL trough chained function calls. The code that creates this possibility was complex and precise, really too hard to understand, maintain develop and refactor; entirely the worst kind. The idea was if we extract this necessarily complex monster into and external reusable library.

Usage

I present the usage of the library with the example below; there are many ways to use it, let's start with the most practically applicable one.

Example sync basic

In this example, you can see the library if you do callback needs to have two of them the first receives the error code that is 0 at the moment only, in the future it will change and the second that is all the parameters you chained trough.

const unlimitedCurry = require('unlimited-curry')
const fn = unlimitedCurry(
  (e, parameters) => {
    //will not return anything, will be execited anyways
  },
    parameters=>`${parameters.data.returnArray[0]}${parameters.data.returnArray[1]}${parameters.data.returnArray[2]}`
  )
const returnValue = await fn('a')('b')('c')()
console.log(returnValue)
expect(returnValue).to.be.equal('abc')

Example async basic

As you see this example looks just a bit different, but his small difference not calling the empty parenthesis makes the first callbacks execution async as well. Technically it is a setTimeout(()=>{}, 0) you can google it, that was enlightening for me, maybe you would enjoy that doing so. Later in this documentation, for now, please consult the source. Maybe this video will help as well.

const unlimitedCurry = require('unlimited-curry')

const fn = unlimitedCurry(
  (e, parameters) => {
    return parameters.data.returnArray[0]
      + parameters.data.returnArray[1]
      + parameters.data.returnArray[2]
  })
const returnValue = await fn('a')('b')('c').p().then(data=>data)
console.log(returnValue)
expect(returnValue).to.be.equal('abc')

If you don't use the promise the p() function, as it is a detached execution you will not be able to get back anything.

split call example

This few lines also comes from the test suite, but you will get how you can use it in real life.

const getMyCurry = () => unlimitedCurry(
  (e, parameters) => {
  },
  parameters=>parameters.data.returnArray[0]
    + parameters.data.returnArray[1]
    + parameters.data.returnArray[2]
)
let fn = getMyCurry()
fn('a')
let returnValue = fn('b', 'c')()
expect(returnValue).to.be.equal('abc')

fn = getMyCurry()
fn('a', 'b')
returnValue =  fn('c')()
expect(returnValue).to.be.equal('abc')

fn = getMyCurry()
fn('a')
fn('b')
returnValue = fn('c')()
expect(returnValue).to.be.equal('abc')

of course it will work with the promis version too.

1.4.13

5 years ago

1.4.11

6 years ago

1.4.1

6 years ago

1.3.5

6 years ago

1.3.4

6 years ago

1.3.3

6 years ago

1.3.2

6 years ago

1.3.1

6 years ago

1.3.0

6 years ago

1.2.8

6 years ago

1.2.7

6 years ago

1.2.4

6 years ago

1.2.3

6 years ago

1.2.2

6 years ago

1.2.1

6 years ago

1.2.0

6 years ago

1.1.14

6 years ago

1.1.13

6 years ago

1.1.12

6 years ago

1.1.9

6 years ago

1.1.8

6 years ago

1.1.7

6 years ago

1.1.6

6 years ago

1.1.5

6 years ago

1.1.3

6 years ago

1.1.2

6 years ago

1.1.1

6 years ago

1.1.0

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago

0.0.2

6 years ago

0.0.1

6 years ago