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 :: angular declare variable in a file 
Javascript :: vue watch deep property 
Javascript :: get value by id js 
Javascript :: javascript get content between tags 
Javascript :: click button when press enter javascript 
Javascript :: rendering htmnl element to DOM 
Javascript :: node readline question 
Javascript :: material ui datepicker remove error 
Javascript :: change mouse highlight color js 
Javascript :: react native touchableopacity 
Javascript :: how to define emojis from your server in discord.js 
Javascript :: mongoose connect to URL of atlas 
Javascript :: https with express 
Javascript :: js window redirect 
Javascript :: function redirect javascript 
Javascript :: javascript array distinct 
Javascript :: javascript create image 
Javascript :: URL scheme "localhost" is not supported. 
Javascript :: how to find length of string in javascript without using length method 
Javascript :: loopback find with limit 
Javascript :: Express’s default X-Powered-By header Disabling 
Javascript :: get full date in javascript 
Javascript :: local storage angular 
Javascript :: longest word javascript 
Javascript :: how to convert new date to dd/mm/yyyy format in javascript 
Javascript :: how to get relative postiion mouse click on element 
Javascript :: JavaScript Using a Temporary Variable 
Javascript :: what is global execution context in javascript 
Javascript :: javascript object dont sort 
Javascript :: convert iso 8601 to utc javascript 
ADD CONTENT
Topic
Content
Source link
Name
3+1 =