Pipe (Functional Programming)
P(propertyName)
Get object property
const obj = name: "Peter" address: street: "123" ; const getName = ;const getStreet = ; console; // => Peterconsole; // => 123
P.invoke(methodNameOrFunction, ...args)
Invoke object method without parameters
const obj = "Peter" ; const getName = ; console; // => Peter
Invoke object method with specified parameters
const obj = type === "home" ? "1234" : "4321" ; const getHomePhone = P;const getWorkingPhone = P; console; // => 1234console; // => 4321
Invoke object method with specified parameters and placeholder
const wrapMe = P; console; // => Before Hello World After
P.if(condition, thenHandler, elseHandler)
Single Conditional
; const isOdd = x % 2; const left = ` is odd`;const right = ` is even`; const fn = P; console; // returns 2 is evenconsole; // returns 1 is odd
P.when(conditions[], unlessHandler)
Multiple Conditionals
const waterWithTemperature = P; ;;;
P.always(value)
Returns a function that always returns the given value
const t = R;; //=> 'Tee' // There are some shorthands:Ptrue; // => truePnull; // => nullPundefined; // => undefinedPempty; // => ''Pzero; // => 0
P.is(operator, value)
Compare value
const equalToZero = P; // or P.is('=', 0)console; // => trueconsole; // => false
There are some various comparisons:
P.is('notEqualTo', value)
P.is('!=', value)
P.is('greaterThan', value)
P.is('>', value)
P.is('lessThan', value)
P.is('<', value)
P.is('greaterOrEqualTo', value)
P.is('>=', value)
P.is('lessOrEqualTo', value)
P.is('<=', value)
P.is('null')
P.is('undefined')
P.is('nil') null or undefined
P.is('empty')
P.is('zero')
P.await(funcReturnsPromise, failHandler)
const login = ; ;
P.and(...conditions)
Returns true if all results are true.
const userNameMustHaveAtLeastSixCharacters = username && usernamelength >= 6;const usernameMustNotContainSpecialCharacters = /^\w+$/;const registerUser = ; /* method 2 const registerUser = P.if( P.and( userNameMustHaveAtLeastSixCharacters, usernameMustNotContainSpecialCharacters ), () => console.log('User registered'), () => console.log('Username is not valid') );*/ ;;;
There are some various of logical functions
P.every(...conditions) ~ P.and
p.some(...conditions) ~ P.or
P.not or P.not(condition)
P.catch(handler)
const doSomethingWrongIf = { if !flag throw 'Invalid operation'; return flag;}; const doSomething = ; ; // => Result is true; // Invalid operation exception thrown