4.6.80 • Published 12 months ago

@zitterorg/fuga-maiores-architecto v4.6.80

Weekly downloads
-
License
MIT
Repository
github
Last release
12 months ago

@zitterorg/fuga-maiores-architecto

@zitterorg/fuga-maiores-architecto lets you chain functions linearly in JavaScript without syntax transformers. It is a combination of the proposed call and pipe operators.

Methods

To invoke a method of any arity, pass the function as the first argument to call (the internal name of the closure returned by pipe) and the rest of the parameters. To extract the result, call it without any parameters.

import { pipe } from '@zitterorg/fuga-maiores-architecto';

const { concat, toUpperCase } = String.prototype;

function exclaim() {
	return this + '!';
}

function prepend(string) {
	return string + this;
}

console.assert(
	pipe
		('hello')
		(concat, ' ', 'world')
		(toUpperCase)
		(exclaim)
		(prepend, '🌎 ')
		()
	=== '🌎 HELLO WORLD!'
);

/*
prepend.call(
	exclaim.call(
		'hello'
			.concat(' ', 'world')
			.toUpperCase()),
	'🌎 ')
*/

Data-First Functions

There are two ways of invoking regular functions. You can either pass in an index as the first parameter or a symbol. For index substitution, type inferencing is supported by up to 10 parameters. For placeholder substitution, it is best to use a unique symbol such as the one exported by @zitterorg/fuga-maiores-architecto: $. For data-first functions, using index substitution and passing 0 is preferred since it's shorter.

import { $, pipe } from '@zitterorg/fuga-maiores-architecto';

function* count() {
	for (let i = 0; ; ++i) {
		yield i;
	}
}

function* take(iterator, length) {
	iterator = iterator[Symbol.iterator]();
	while (length-- > 0) {
		const result = iterator.next();
		if (result.done) {
			return;
		}
		yield result.value;
	}
}

function* map(iterator, callback) {
	for (const value of iterator) {
		yield callback(value);
	}
}

function reduce(iterator, callback, accumulator) {
	for (const value of iterator) {
		accumulator = callback(accumulator, value);
	}
	return accumulator;
}

const double = x => x * 2;
const add = (x, y) => x + y;

console.assert(
	pipe
		(count())
		(0, take, 10)
		(0, map, double)
		(0, reduce, add, 0)
		()
	=== 90
);

console.assert(
	pipe
		(count())
		($, take, $, 10)
		($, map, $, double)
		($, reduce, $, add, 0)
		()
	=== 90
);

/*
reduce(
	map(
		take(
			count(),
			10),
		double),
	add,
	0);
*/

Data-Last Functions

Data-last functions are invoked the same way as data-first functions, except you'll have to pass in -1 instead of 0. Placeholder substitution works the same.

import { $, pipe } from '@zitterorg/fuga-maiores-architecto';

function add(x, y, z) {
	return x + y + z;
}

console.assert(
	pipe
		(3)
		(-1, add, 1, 2)
		()
	=== 6
);

console.assert(
	pipe
		(3)
		($, add, 1, 2, $)
		()
	=== 6
);

/*
add(1, 2, 3);
*/

Data-N Functions

You're not restricted to 0 and -1 as indexes.

import { $, pipe } from '@zitterorg/fuga-maiores-architecto';

function add(x, y, z) {
	return x + y + z;
}

console.assert(
	pipe
		(2)
		(1, add, 1, 3)
		()
	=== 6
);

console.assert(
	pipe
		(2)
		($, add, 1, $, 3)
		()
	=== 6
);

/*
add(1, 2, 3);
*/

Internals

As mentioned earlier, pipe returns a function call that closes over the passed in value referred to as the accumulator. Please keep in mind that the accumulator is overwritten whenever call is invoked with a function (referred to as the reducer). Unless no parameters are passed to call, it will always return itself.

import { pipe } from '@zitterorg/fuga-maiores-architecto';

// reducer
function increment() {
	return this + 1;
}

// accumulator
const initial = 0;

// closure
const call = pipe(initial);

const a = call(increment);
console.assert(a() === 1);

const b = call(increment);
console.assert(b() === 2);

console.assert(a() === 2);
console.assert(b() === 2);
console.assert(a === b);
weakmapresolvemonorepomkdirpReflect.getPrototypeOftoArraytimeextensionprogresswordwrapWebSockets_.extenditerateObject.getPrototypeOfschemereactlinkwhatwgString.prototype.matchAlleventsstyled-componentsreducercachecommandagentconfigurablerandomviewwebsitelibphonenumbersomeinternalwaapipipeURLSearchParamsiterationoptionsettingspositivebuffersnodejsidleUint8ClampedArrayincludesvaluesshebanges5tc39parentasyncECMAScript 6eslint-plugindataViewStreamswrapwafmapreduceURLprivate databrowserutilitydeep-cloneuninstallargs__proto__moduleFloat64Arrayrfc4122deepcopycallbindjsdiffbrowserslistsyntaxwriteslicerecursiveform-validationpnpm9negativeoncepostcssnativeRegExp#flagsastoptimistgetoptprunedeep-copyString.prototype.trimautoprefixertoolssortvalidationsymlinktypeofregular expressionsrgbeslintconfigECMAScript 2023hashcloudformationhas-ownformmimeupkarmaweaksetfullfast-clonecloudfrontESnextuuidesES2023stylelimites-shimsguidframeworkratelimitBigInt64ArraybeanstalkimmutablejQueryclass-validatorexpressionECMAScript 2022readablestreamajaxtermamazonawaitObject.valuesES2020toobjectdefaultObject.isjavascriptenvironmentmakebundlerfile systemruntimebrowserlistrdstyped arrayconfigwalkingstartdirpackagesparserdebugESinferenceexecES7sets3SetsafekeyloggerstructuredClonepathtrimRightartfull-widthcallbackgetPrototypeOflruhasOwnPropertyECMAScript 2016bundlingloggingsameValueZerovars256globalperformancedependency managerRegExp.prototype.flagsxdghttpsES8setPrototypeOfecmascriptyamlchildtypescriptbyteOffsetremovegenericsArray.prototype.flatMaparraypropertiesformateslintplugindescriptionclitoolkitsidefast-deep-copyjsdomxdg-openmobilecssawesomesauceintrinsicregular expressiongetintrinsicxtermerrorReactiveExtensionsurlsfastcopywebisdatautilitiestestershamindicatorfastifyPromisecloudwatch[[Prototype]]enumerableIteratorcodesMicrosoftUnderscoreTypeScript3dES5ec2l10nfunctionwaitlogassertstouchtypeerrorduplexposechaiArray.prototype.flat$.extendponyfillprotobufcjkhelpersreact-hook-formObject.entriesECMAScript 3chromeUint16ArraylengthflagsloadingapiglobalsfunctionalHyBiES2015formattingdefinePropertyflageditorcharactersgesturesbyteLengthES6takeSymboles70deeproutingnodevariablesroute53symbolsajvmime-dbMapECMAScript 7typesaferobusttapvisualwhichrequesttscore-jsiecall-bindstringifyrm -rfRFC-6455streams-0statelessreuseArray.prototype.includesECMAScript 2021ReactiveXhardlinksbddphoneStreamtrimEndthroatcolumnsprettydatastructurees6real-timematchAllreact-testing-librarycomparerm -frcontainscopygroupBylastidRxworkerprocesssearchroutefast-deep-cloneswfeventDispatcherserializetestzodcollectionargumentses2015breaktapea11yflatinstallproxyschematypedarrayssimpledblinewrapes2016consoletoStringTagfixed-widthdataviewregexpwarningECMAScript 2017animationterminalhelperimmerparsingcallendpointES2021momentUint32ArrayansiiconvwidthindefinePushfindLastexeTypeBoxtostringtagspawnspinnermimetypesqueueMicrotaskpromisetslibslotdomiamzerobusyloadbalancinggetOwnPropertyDescriptorimportxhrECMAScript 2015cmdequalityJSONcoercibleicuhookstoSortedspinnerscoreInt16ArraystyleguidecompileremojidropelectronES2017inputcode pointslookchinesequeryyupcolorforEachcharsetbannerawsAsyncIteratordom-testing-librarysuperstructstreamES2016performantefficientemitmkdirassignvpcredactWeakSetextendfpsjshintfilespeedfsjsargvdeterministicstarterES2022validatesyntaxerror.envqueueWebSocketpostcss-pluginasciiArray.prototype.filtersns@@toStringTagprotoemrexecutableairbnbprivateequalespreekinesiscreateStyleSheetvestlockfileclientautoscalingWeakMapoffsetfindSymbol.toStringTagqsfunction.lengthreadabletypeshigher-orderreact-hooksquerystringlimitedfastclonetraversewgetfetchmochaaccessorcollection.es6jsonpathlazycallboundsetterdependencieswalksqsObject.fromEntrieshascolourfiltertrimredux-toolkitbindmatchesgdprjasmineECMAScript 2020npminspectObservablenumberapollodescriptorestreepreserve-symlinksownthreeserializationebsjapanesestylesfinduppropCSSStyleDeclarationidentifierspopmotionArrayBufferconcurrencyregexECMAScript 2018es8validmapjestjsondynamodbconvertunicodearraysstablefigleteverymergesuperagentES3hasOwnrequiretaskentriesfast-copymruenvargumentRxJStrimStartfastisConcatSpreadablehookformchannelgetassertionprefixlocationFunction.prototype.namegroupdebuggerappECMAScript 2019command-linevalueworkflowUint8ArrayArray.prototype.findLasttypanionpushurltrimLeftJSON-SchemapropertythrottleconsumewordbreakrmInt8Arraystoragegatewayinternal slotwritablecloudtrailObject.assigndiffcheckcurlmulti-packageObjectYAMLBigUint64ArrayFloat32Arraylanguagecircularobjectextraenderelbratespringmetadataparentstddglobcensori18nfunctionsquoteomitES2018bufferfind-upiteratornopechromiumaccessibilityminimalTypedArrayes2018sharedlook-uptextArray.prototype.flattenArray.prototype.containstypedfolderkoreanArraytelephoneavapackage.jsoncolumnrangeerrordateflattennegative zeroglacierformslistenerstypedarrayreact poseArrayBuffer.prototype.sliceeast-asian-widthstreams2polyfillsetImmediateconcatMappluginreducelintes2017cloneutiljsxmkdirsoutputObject.definePropertysespromisesgraphqlreduxECMAScript 5es-shim APIconcatprotocol-buffershttprmdirreadtypeargparseobjassertkeysstylingdirectoryprototypeinstallerttyeventEmitternameObservableseslintstringifiersortedcommanderpicomatchdotenvcall-boundtestingredirectframersequencerapidmake dirsymlinksfindLastIndexbyteenvironmentsdescriptorses-abstractimportexportstringcolorsreact animationshrinkwraplaunchCSSArrayBuffer#slicebluebirdescapecomputed-typescryptofullwidthworkspace:*css-in-jsInt32Arrayregularserializernamesdeepclonecharacterspecscheme-validationfrompatchsymbolelasticachemoveopensshimio-tsopenergetterinvariantpackage manager
4.6.80

12 months ago

4.6.77

12 months ago

4.6.78

12 months ago

4.6.76

12 months ago

4.6.79

12 months ago

4.6.73

12 months ago

4.6.74

12 months ago

4.6.75

12 months ago

4.5.72

12 months ago

4.5.73

12 months ago

4.5.71

12 months ago

4.5.70

12 months ago

4.5.69

12 months ago

4.5.67

12 months ago

4.5.68

12 months ago

3.5.58

1 year ago

3.4.47

1 year ago

3.5.57

1 year ago

3.4.48

1 year ago

3.5.56

1 year ago

3.4.49

1 year ago

3.5.55

1 year ago

3.5.54

1 year ago

3.5.53

1 year ago

3.5.52

1 year ago

3.5.51

1 year ago

3.4.40

1 year ago

3.4.41

1 year ago

3.4.42

1 year ago

3.4.43

1 year ago

3.4.44

1 year ago

3.4.45

1 year ago

3.3.33

1 year ago

3.5.59

1 year ago

3.4.46

1 year ago

3.3.34

1 year ago

3.5.50

1 year ago

3.5.62

1 year ago

3.4.50

1 year ago

4.5.62

1 year ago

4.5.65

12 months ago

4.5.66

12 months ago

4.5.63

1 year ago

4.5.64

1 year ago

3.5.61

1 year ago

3.5.60

1 year ago

2.3.33

1 year ago

2.3.32

1 year ago

3.4.36

1 year ago

3.4.37

1 year ago

3.4.38

1 year ago

3.4.39

1 year ago

3.4.34

1 year ago

3.4.35

1 year ago

2.3.31

1 year ago

1.3.30

1 year ago

2.3.30

1 year ago

1.3.28

1 year ago

1.3.29

1 year ago

1.3.25

1 year ago

1.3.26

1 year ago

1.3.27

1 year ago

1.2.18

1 year ago

1.2.19

1 year ago

1.3.19

1 year ago

1.3.20

1 year ago

1.3.21

1 year ago

1.3.24

1 year ago

1.3.22

1 year ago

1.3.23

1 year ago

1.2.16

1 year ago

1.2.17

1 year ago

1.2.14

1 year ago

1.2.15

1 year ago

1.2.13

1 year ago

1.2.12

1 year ago

1.2.8

1 year ago

1.2.9

1 year ago

1.2.10

1 year ago

1.2.11

1 year ago

1.2.7

1 year ago

1.2.6

1 year ago

1.2.5

1 year ago

1.1.5

1 year ago

1.1.4

1 year ago

1.1.3

1 year ago

1.1.2

1 year ago

1.1.1

1 year ago

1.1.0

1 year ago

1.0.0

1 year ago