views:

47

answers:

1

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.

+1  A: 

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.

Franci Penov
There is no methods and an interface, it's totally functional
sid3k
thank you for the explanation in the update.
sid3k