Project

General

Profile

Feature #17043

Updated by sawa (Tsuyoshi Sawada) over 3 years ago

Ruby beautifully integrates Functional and Object-Oriented Programming, and there's more moving in the direction of supporting Functional Programming. A generalization of the Proc interface would enable users to integrate a functional approach into their classic OOP design patterns. One of the obvious examples would be "Command" objects. 

 Also, generic structures, structures which Ruby has as great support for. Hash now has `to_proc`.    But, it'd be great to be able to treat sets as predicate functions. 

 I've put together a prototype that I've found useful in my own work here: https://github.com/delonnewman/invokable. 

 It works like Enumerable; Enumerable, it can be included in any class that implements a `call` method. Then you get `to_proc`, `curry`, `<<` and `>>` for right and left composition, and `memoize`. More could be added. If you include `Invokable::Command`, `Invokable::Command` you can treat your "Command" object as an automatically curried function. 

Back