Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

why use currying

const createURL = baseURL => {
  const protocol = "https";

  // we now return a function, that accepts a 'path' as an argument
  return path => {
    return `${protocol}://${baseURL}/${path}`;
  };
};

// we create a new functions with the baseURL value in it's closure scope
const createSiteURL = createURL("mysite.com");
const createCareersURL = createURL("mysite-careers.com");

// create URLs for our main site
const homeURL = createSiteURL("");
const loginURL = createSiteURL("login");
const productsURL = createSiteURL("products");
const contactURL = createSiteURL("contact-us");

// create URLs for our career site
const careersHomeURL = createCareersURL("");
const careersLoginURL = createCareersURL("login");
Comment

what is currying

a technique that applies a function 
to its arguments one at a time, with 
each application returning a new function 
that accepts the next argument.
Comment

Understanding Currying

/**
 * The underlying base function is "add" which takes 3 arguments and return their sum.
 */
const add = (a, b, c) => a + b + c;

/**
 * We need such a function which will transform the base function such that
 * it can also process its argument one by one.
 */
const curry = (baseFunc) => {
  // TODO: Do something with it.
};

const add3 = curry(add);
Comment

PREVIOUS NEXT
Code Example
Javascript :: convert all styles to inline style javascript 
Javascript :: classlist toggle 
Javascript :: working with multiple db in single query mongodb 
Javascript :: javascript multiple startswith 
Javascript :: variables in javascript 
Javascript :: ex:javascript 
Javascript :: asyncio.sleep in javascript 
Javascript :: map function javascript 
Javascript :: Force users to update your application in React Native 
Javascript :: get week number of month from date moment 
Javascript :: /function 
Javascript :: what is a node 
Javascript :: else in javascript 
Javascript :: js alerts 
Javascript :: express middleware status code always 200 
Javascript :: mongodb mongoose concatenate two values before get 
Javascript :: js multibyte string length 
Javascript :: javascript random alphanumeric string 
Javascript :: dart get vfirst key value of map 
Javascript :: display only initials from full name reactjs 
Javascript :: mongoose query same field with different values 
Javascript :: Pure JavaScript Send POST NO JQUERY 
Javascript :: crypto 32 characers encryption node js 
Javascript :: kjkjl 
Javascript :: How to use browser-sync to serve files easily 
Javascript :: append string in variable using jquery in each loop 
Javascript :: Map the peoples of Ray such as their first name comes first in the string in js 
Javascript :: unexpected template string expression no-template-curly-in-string react 
Javascript :: how to install reveal.js from node 
Javascript :: where to set cdvMinSdkVersion 
ADD CONTENT
Topic
Content
Source link
Name
7+6 =