6

From a function with multiple parameters can we partially apply just one or two parameters to it returning a new function that takes the remaining parameters?

Javascript example using Ramda

function buildUri (scheme, domain, path) {
  return `${scheme}://${domain}/${path}`
}

const buildHttpsUri = R.partial(buildUri, ['https']);

const twitterFavicon = buildHttpsUri('twitter.com', 'favicon.ico');
atreeon
  • 21,799
  • 13
  • 85
  • 104

1 Answers1

5

You can just forward to another function

String buildUri (String scheme, String domain, String path) {
  return `${scheme}://${domain}/${path}`
}

String buildHttpsUri(String domain, String path) => buildUri('https', domain, path);
Günter Zöchbauer
  • 623,577
  • 216
  • 2,003
  • 1,567