In functional programming you often want to apply a function partly. A simple example is a function add
.
It would be nice if we could use add
like:
var res2 = add(1, 3); // => 4
var add10To = add(10);
var res = add10To(5); // => 15
Use: for testing against email regex | |
ref: http://codefool.tumblr.com/post/15288874550/list-of-valid-and-invalid-email-addresses | |
List of Valid Email Addresses | |
email@example.com | |
firstname.lastname@example.com | |
email@subdomain.example.com | |
firstname+lastname@example.com |
We have absolutely no idea what we're doing in tech. Please explain the utmost basic things to us.
We only do web design. Our whole reason of being in tech is to make things pretty. Consider us the doilies of the industry.
We're not laughing about your joke, so we clearly need you explain it to us. In great detail.
We're only in tech to find a husband, boyfriend or generally to get laid.
const I = x => x | |
const K = x => y => x | |
const A = f => x => f (x) | |
const T = x => f => f (x) | |
const W = f => x => f (x) (x) | |
const C = f => y => x => f (x) (y) | |
const B = f => g => x => f (g (x)) | |
const S = f => g => x => f (x) (g (x)) | |
const S_ = f => g => x => f (g (x)) (x) | |
const S2 = f => g => h => x => f (g (x)) (h (x)) |
// instanceof is a prototype identity check. | |
// NOT a type check. | |
// That means it lies across execution contexts, | |
// when prototypes are dynamically reassigned, | |
// and when you throw confusing cases like this | |
// at it: | |
function foo() {} | |
const bar = { a: 'a'}; |
// to, from are awkward here. generateReport only needs them to send an email | |
const generateReport = (to, from, data) => | |
mungeData(data, (warnings, munged) => | |
renderReport(munged, (report) => emailReport(to, from, report))) | |
generateReport(“info@reports.com”, “app@test.net”, {some: ‘data’}) | |
// if emailReport was curried, we could pass in the emailer |
<div>{"<"} Less than, {">"} greater than </div> |
function translateError(msg) { | |
var newErr = new Error(msg); // placed here to get correct stack | |
return e => { | |
newErr.originalError = e; | |
throw newErr; | |
} | |
} | |
async function asyncTask() { | |
const user = await UserModel.findById(1).catch(translateError('No user found')) |