What is the Evangelist?
Evangelist is a set of helper methods that are useful and reusable for base functional programming requirements such as function composition, function decoration, event dispatching and emitting, etc.
Plus, as a library, Evangelist is completely tree-shaking-friendly. Your favorite module bundler can easily inline the functionality you need with no extra configuration, instead of bundling the whole Evangelist package.
Quick start
Execute npm install evangelist
to install evangelist and its dependencies into your project directory.
Usage of modules
compose(...functionsForComposition)
import compose from 'evangelist/compose';
const lower = x => x.toLowerCase();
const chars = x => x.replace(/[^\w \-]+/g, '');
const spaces = x => x.split(' ');
const dashes = x => x.join('-');
const slug = compose(lower, chars, spaces, dashes);
const message = slug('Hello World!');
console.log(`slug: ${message}`);
curry(targetFunction, ...argumentsToBePrepended)
import curry from 'evangelist/curry';
const sum = (a, b) => a + b;
const sumWith5 = curry(sum, 5);
const result = sumWith5(3);
console.log(`result: ${result}`);
curryRight(targetFunction, ...argumentsToBeAppended)
import curryRight from 'evangelist/curryRight';
const dec = (a, b) => a - b;
const decWith5 = curry(dec, 5);
const result = decWith5(3);
console.log(`result: ${result}`);
decorate(functionToDecorate, decoratorFunction)
import decorate from 'evangelist/decorate';
let generator = () => 5;
generator = decorate(generator, (func) => func() * 2);
generator = decorate(generator, (func) => func() + 1);
console.log(`generated: ${generator()}`);
dispatcher(initialState, mutators) (awaitable)
import dispatcher from 'evangelist/dispatcher';
const initialState = { quarter: 1, year: 2018, sum: 1 };
const actionAdd5 = (state, next) => next({ ...state, sum: state.sum + 5 });
const actionDiv2 = (state, next) => next({ ...state, sum: state.sum / 2 });
dispatcher(initialState, [ actionAdd5, actionDiv2 ])
.then(state => console.log(`new state is: ${JSON.stringify(state)}`));
dispatcher(initialState, mutators, subscribers) (awaitable)
import dispatcher from 'evangelist/dispatcher';
const initialState = { quarter: 1, year: 2018, sum: 1 };
const actionAdd5 = (state, next) => next({ ...state, sum: state.sum + 5 });
const actionDiv2 = (state, next) => next({ ...state, sum: state.sum / 2 });
const logger = (x) => console.log('INFO', x);
dispatcher(initialState, [ actionAdd5, actionDiv2 ], [ logger ])
.then(state => console.log(`new state is: ${JSON.stringify(state)}`));
emitter(events, eventName, eventParameters) (awaitable)
import emitter from 'evangelist/emitter';
const subscriberOne = (value) => console.log(`subscriberOne had value ${value}`);
const subscriberTwo = (value) => console.log(`subscriberTwo had value ${value}`);
const events = {
printToConsole: [ subscriberOne, subscriberTwo ],
};
emitter(events, 'printToConsole', [ 5 ]);
emitter(events, eventName, eventParameters, subscribers) (awaitable)
import emitter from 'evangelist/emitter';
const subscriberOne = (value) => console.log(`subscriberOne had value ${value}`);
const subscriberTwo = (value) => console.log(`subscriberTwo had value ${value}`);
const logger = (x) => console.log('INFO', x);
const events = {
printToConsole: [ subscriberOne, subscriberTwo ],
};
emitter(events, 'printToConsole', [ 5 ], [ logger ]);
iterate(iterable, func) (awaitable)
import iterate from 'evangelist/iterate';
import compose from 'evangelist/compose';
const generator = function* () {
yield 'http://localhost/samples/1';
yield 'http://localhost/samples/2';
yield 'http://localhost/samples/3';
};
const fetchUrl = async function (url) {
const response = await fetch(url);
const document = await response.json();
return document.value;
}
const add5 = async value => await value + 5;
const printToConsole = async value => { console.log(await value); };
iterate(
generator(),
compose(fetchUrl, add5, printToConsole),
);
Todo List
See GitHub Projects for more.
Requirements
License
Apache 2.0, for further details, please see LICENSE file
Contributing
See contributors.md
It is publicly open for any contribution. Bugfixes, new features and extra modules are welcome.
- To contribute to code: Fork the repo, push your changes to your fork, and submit a pull request.
- To report a bug: If something does not work, please report it using GitHub Issues.
To Support
Visit my patreon profile at patreon.com/eserozvataf