evangelist
🌟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
or yarn add evangelist
to install evangelist and its dependencies into your project directory.
Usage of modules
compose(...functionsForComposition)
; // compose - slug sampleconst lower = x;const chars = x;const spaces = x;const dashes = x; const slug = ; const message = ; // outputs 'slug: hello-world'console;
curry(targetFunction, ...argumentsToBePrepended)
; // curry - sum sampleconst sum = a + b; const sumWith5 = ; const result = ; // outputs 'result: 8'console;
curryRight(targetFunction, ...argumentsToBeAppended)
; // curryRight - sum sampleconst dec = a - b; const decWith5 = ; const result = ; // outputs 'result: -2'console;
decorate(functionToDecorate, decoratorFunction)
; // decorate - calculator samplelet 5;generator = ;generator = ; // outputs: 'generated: 11'console;
dispatcher(initialState, mutators) (awaitable)
; // dispatcher - state mutation sampleconst initialState = quarter: 1 year: 2018 sum: 1 ; const actionAdd5 = ;const actionDiv2 = ; // outputs 'new state is: {"quarter":1,"year":2018,"sum":3}' ;
dispatcher(initialState, mutators, subscribers) (awaitable)
; // dispatcher - action logger sampleconst initialState = quarter: 1 year: 2018 sum: 1 ; const actionAdd5 = ;const actionDiv2 = ; const logger = console; /* outputs: INFO { action: 'actionAdd5', previousState: { quarter: 1, year: 2018, sum: 1 }, newState: { quarter: 1, year: 2018, sum: 6 } } INFO { action: 'actionDiv2', previousState: { quarter: 1, year: 2018, sum: 6 }, newState: { quarter: 1, year: 2018, sum: 3 } } new state is: {"quarter":1,"year":2018,"sum":3}'*/ ;
emitter(events, eventName, eventParameters) (awaitable)
; // emitter - static pub/sub sampleconst subscriberOne = console;const subscriberTwo = console; const events = printToConsole: subscriberOne subscriberTwo ; /* outputs: subscriberOne had value 5 subscriberTwo had value 5*/;
emitter(events, eventName, eventParameters, subscribers) (awaitable)
; // emitter - event logger sampleconst subscriberOne = console;const subscriberTwo = console; const logger = console; const events = printToConsole: subscriberOne subscriberTwo ; /* outputs: INFO { event: 'printToConsole', subscriber: 'subscriberOne', args: [ 5 ] } subscriberOne had value 5 INFO { event: 'printToConsole', subscriber: 'subscriberTwo', args: [ 5 ] } subscriberTwo had value 5*/;
iterate(iterable, func) (awaitable)
;; // iterate - url fetcher exampleconst generator = { 'http://localhost/samples/1'; // { value: 1 } 'http://localhost/samples/2'; // { value: 2 } 'http://localhost/samples/3'; // { value: 3 }}; const fetchUrl = { const response = await ; const document = await response; return documentvalue;} const add5 = async await value + 5;const printToConsole = async { console; }; /* outputs: value is 6 value is 7 value is 8*/;
Todo List
See GitHub Projects for more.
Requirements
- node.js (https://nodejs.org/)
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.