Remix.run Logo
jhhh 6 hours ago

A benefit to using the currying style is that you can do work in the intermediate steps and use that later. It is not simply a 'cool' way to define functions. Imagine a logging framework:

  (log configuration identifier level format-string arg0 arg1 ... argN)
  
After each partial application step you can do more and more work narrowing the scope of what you return from subsequent functions.

  ;; Preprocessing the configuration is possible
  ;; Imagine all logging is turned off, now you can return a noop
  (partial log conf)
  ;; You can look up the identifier in the configuration to determine what the logger function should look like
  (partial log conf id)
  ;; You could return a noop function if the level is not enabled for the particular id
  (partial log config id level)
  ;; Pre-parsing the format string is now possible
  (partial log conf id level "%time - %id")
  
In many codebases I've seen a large amount of code is literally just to emulate this process with multiple classes, where you're performing work and then caching it somewhere. In simpler cases you can consolidate all of that in a function call and use partial application. Without some heroic work by the compiler you simply cannot do that in an imperative style.