It would be nice to create ORM like Active Record or Hibernate, it should process chained queries like this:
User = User:new():for_login(«stackoverflow_admin»):for_password(«1984»):load().
How can we do this? Or just like that, in one line - or at least similar in spirit and meaning.
Maybe there are some preprocessing tools that can help in this?
Although I found @zxq9 answer so informative, mentioning the history of imitating Java-like OOP style in Erlang could be helpful.
Method chaining needs state and there were efforts to include "Stateful Modules" into Erlang:
Parametrized Module: A proposal that lets developer to implement modules that accept parameters and hold them as a module state to use in its functions. Long ago it had been added to Erlang as an experimental feature, but the technical board decided to remove the syntactic support for this feature in R16 because of both conceptual and practical incompatibilities that it caused.
Tuple Module: A backwards compatibility for parametrized module, which also introduced in details in chapter 8 of Programming Erlang (Second Edition), but there is no official documentation for it and it is still a controversial feature that introduces complexity and ambiguity with no power in the Erlang way.
Imitating coding style of languages with different paradigms like Ruby and Java in Erlang which is a functional language with different concepts could be exciting but with no added value.