Nucleotides are the building blocks of JavaScript programs. They are simple, useful functions with well-understood semantics.
Nucleotides fix two aspects of JavaScript which hinder functional programming: operators and methods.
The problem with operators
In functional programming it's common to pass one function to another function. This is possible in JavaScript because functions are values. Operators, on the other hand, are not values so cannot be passed as arguments. The workaround is to use anonymous functions:
var sum = nums;
There is a nucleotide for each operator. nucleotides.operator.binary['+'], in this case:
var sum = nums;
The problem with methods
The semantics of JavaScript methods are incompatible with most higher-order functions. Methods must be wrapped so as to behave like regular functions:
var tags = str;
There is a nucleotide for each built-in method. nucleotides.string.trim, in this case:
var tags = str;
Nucleotides
The name of each mutator function is suffixed with !
. This prevents
unintentional mutation, draws attention to places where mutation does
occur, and reserves the unsuffixed names for future use.
The following nucleotides are available:
- nucleotidesoperatornew- nucleotidesoperatorunarytypeof- nucleotidesoperatorunary'+'- nucleotidesoperatorunary'-'- nucleotidesoperatorunary'~'- nucleotidesoperatorunary'!'- nucleotidesoperatorbinary'*'- nucleotidesoperatorbinary'/'- nucleotidesoperatorbinary'%'- nucleotidesoperatorbinary'+'- nucleotidesoperatorbinary'-'- nucleotidesoperatorbinary'<<'- nucleotidesoperatorbinary'>>'- nucleotidesoperatorbinary'>>>'- nucleotidesoperatorbinary'<'- nucleotidesoperatorbinary'>'- nucleotidesoperatorbinary'<='- nucleotidesoperatorbinary'>='- nucleotidesoperatorbinaryinstanceof- nucleotidesoperatorbinaryin- nucleotidesoperatorbinary'=='- nucleotidesoperatorbinary'!='- nucleotidesoperatorbinary'==='- nucleotidesoperatorbinary'!=='- nucleotidesoperatorbinary'&'- nucleotidesoperatorbinary'^'- nucleotidesoperatorbinary'|'- nucleotidesoperatorbinary'&&'- nucleotidesoperatorbinary'||'- nucleotidesarraytoString- nucleotidesarraytoLocaleString- nucleotidesarrayjoin- nucleotidesarray'pop!'- nucleotidesarray'push!'- nucleotidesarrayconcat- nucleotidesarray'reverse!'- nucleotidesarray'shift!'- nucleotidesarray'unshift!'- nucleotidesarrayslice- nucleotidesarray'splice!'- nucleotidesarray'sort!'- nucleotidesarrayfilter- nucleotidesarrayforEach- nucleotidesarraysome- nucleotidesarrayevery- nucleotidesarraymap- nucleotidesarrayindexOf- nucleotidesarraylastIndexOf- nucleotidesarrayreduce- nucleotidesarrayreduceRight- nucleotidesbooleantoString- nucleotidesbooleanvalueOf- nucleotidesdatetoString- nucleotidesdatetoDateString- nucleotidesdatetoTimeString- nucleotidesdatetoLocaleString- nucleotidesdatetoLocaleDateString- nucleotidesdatetoLocaleTimeString- nucleotidesdatevalueOf- nucleotidesdategetTime- nucleotidesdategetFullYear- nucleotidesdategetUTCFullYear- nucleotidesdategetMonth- nucleotidesdategetUTCMonth- nucleotidesdategetDate- nucleotidesdategetUTCDate- nucleotidesdategetDay- nucleotidesdategetUTCDay- nucleotidesdategetHours- nucleotidesdategetUTCHours- nucleotidesdategetMinutes- nucleotidesdategetUTCMinutes- nucleotidesdategetSeconds- nucleotidesdategetUTCSeconds- nucleotidesdategetMilliseconds- nucleotidesdategetUTCMilliseconds- nucleotidesdategetTimezoneOffset- nucleotidesdate'setTime!'- nucleotidesdate'setMilliseconds!'- nucleotidesdate'setUTCMilliseconds!'- nucleotidesdate'setSeconds!'- nucleotidesdate'setUTCSeconds!'- nucleotidesdate'setMinutes!'- nucleotidesdate'setUTCMinutes!'- nucleotidesdate'setHours!'- nucleotidesdate'setUTCHours!'- nucleotidesdate'setDate!'- nucleotidesdate'setUTCDate!'- nucleotidesdate'setMonth!'- nucleotidesdate'setUTCMonth!'- nucleotidesdate'setFullYear!'- nucleotidesdate'setUTCFullYear!'- nucleotidesdatetoGMTString- nucleotidesdatetoUTCString- nucleotidesdategetYear- nucleotidesdate'setYear!'- nucleotidesdatetoISOString- nucleotidesdatetoJSON- nucleotidesfunctionbind- nucleotidesfunctiontoString- nucleotidesfunctioncall- nucleotidesfunctionapply- nucleotidesnumbertoString- nucleotidesnumbertoLocaleString- nucleotidesnumbervalueOf- nucleotidesnumbertoFixed- nucleotidesnumbertoExponential- nucleotidesnumbertoPrecision- nucleotidesobjecttoString- nucleotidesobjecttoLocaleString- nucleotidesobjectvalueOf- nucleotidesobjecthasOwnProperty- nucleotidesobjectisPrototypeOf- nucleotidesobjectpropertyIsEnumerable- nucleotidesobject__defineGetter__- nucleotidesobject__lookupGetter__- nucleotidesobject__defineSetter__- nucleotidesobject__lookupSetter__- nucleotidesregexpexec- nucleotidesregexptest- nucleotidesregexptoString- nucleotidesregexpcompile- nucleotidesstringvalueOf- nucleotidesstringtoString- nucleotidesstringcharAt- nucleotidesstringcharCodeAt- nucleotidesstringconcat- nucleotidesstringindexOf- nucleotidesstringlastIndexOf- nucleotidesstringlocaleCompare- nucleotidesstringmatch- nucleotidesstringreplace- nucleotidesstringsearch- nucleotidesstringslice- nucleotidesstringsplit- nucleotidesstringsubstring- nucleotidesstringsubstr- nucleotidesstringtoLowerCase- nucleotidesstringtoLocaleLowerCase- nucleotidesstringtoUpperCase- nucleotidesstringtoLocaleUpperCase- nucleotidesstringtrim- nucleotidesstringtrimLeft- nucleotidesstringtrimRight- nucleotidesstringlink- nucleotidesstringanchor- nucleotidesstringfontcolor- nucleotidesstringfontsize- nucleotidesstringbig- nucleotidesstringblink- nucleotidesstringbold- nucleotidesstringfixed- nucleotidesstringitalics- nucleotidesstringsmall- nucleotidesstringstrike- nucleotidesstringsub- nucleotidesstringsup
Each of the "method" functions above will be defined only if the environment provides the method. For example, nucleotides.string.trim will be defined only if String.prototype.trim is defined.