functional-programmingdartpartial-application

Is it possible to utilise partial application in Dart (partial / apply / fixing arguments)


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');

Solution

  • 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);