Search code examples
functional-programmingnamingchainingmethod-chaining

Naming Suggestions For A Function Providing Chaining In A Different Way


I've coded an experimental function which makes passed objects chainable by using high order functions. It's name is "chain" for now, and here is a usage example;

chain("Hello World")
  (print) // evaluates print function by passing "Hello World" object.
  (console.log,"Optional","Parameters")
  (returnfrom) // returns "Hello World"

It looks lispy but behaves very different since it's coded in a C based language, I don't know if there is a name for this idiom and I couldn't any name more suitable than "chain".

Any ideas, suggestions?

edit: "with" sounds very suitable name but it's a reserved word in the language I'm working on.


Solution

  • This API design pattern is usually called a Fluent interface.

    Update: Whether the actual implementation of a fluent interface is in object-oriented language is irrelevant. It's the pattern of passing a context to achieve the feeling of a "code flow", which seems exactly what you are aiming to do.

    Of course, what the pattern name is does not actually answer your question. :-)

    As you noted, the best choice for naming your actual function would be with. Second best would be using.