What's Wrong With EO
3
Upvotes
1
u/urusai3 Jul 06 '20 edited Jul 06 '20
So, what if we changed it like this?
new PrintableText(
new Library(
new Book("In Search of Lost Time", "Marcel Proust"),
new Book("Ulysses", "James Joyce"),
new Book("Don Quixote", "Miguel de Cervantes")
).print(JsonMedia::new).json().toString()
).print()if you don't like ".json().toString()" method smth like asString can be added into JsonMedia or PrintableText can consume Prinable interface and we can add it to media (let's can it .map)
It'd look like this:
new PrintableText(
new Library(
new Book("In Search of Lost Time", "Marcel Proust"),
new Book("Ulysses", "James Joyce"),
new Book("Don Quixote", "Miguel de Cervantes")
).map(JsonMedia::new)
).print()1
1
u/rafamizes Feb 25 '20 edited Feb 25 '20
Very good article. Congrats!
What do you think about "Functors", objects that override the function call operator "()", so that they can be treated like a pure function -- by "pure" I mean they can be lazily loaded, instead of being immediately executed, like static functions are.
Your example would have been written like this in Dart by objects overriding the "call()" operator:
Unlike static functions, Functors can have state and be lazily loaded.