Fan with combinators: Kestrel sign

Fan with combinators: Kestrel sign
Average rating: 0
(0 votes)

Thanks! You’ve rated this material!

Fan with combinators: Kestrel sign. Did you use Kestrel in ruby? This pretty neat combinator, that can give you so much power. Originally it’s called K and looks like this:

Kxy = y

Did you have it? It returns you only one element if you give him two.

K = lambda x.lambda y.x

As lambda expression.

Ruby is great language. It has Object.tap method which look like kestrel. And feels like kestrel. Object.tap return object instance, on with he was called every time you give him a block.  So it’s really shines when you can do some side effects in your code and you want chain them out and want to use your object.
What you can do with this?  You can do literally everything with given Object. And nevertheless you will receive it after every block call.

User.new.tap {  |user|  log(user.come)  }.tap {  |user|   log(user.eat  }.eat(:burger)

Perfect! You logged out user actions and nevertheless obtain your user from tap. And send him message to do something else. 

Rate this article, if you like it

Thanks! You’ve rated this material!

Got a project? Let's discuss it!

Mailing & Legal Address

Syndicode Inc. 340 S Lemon Ave #3299, Walnut CA, 91789, USA

Visiting & Headquarters address
Kyiv Sofiivska 1/2a, 01001, Kyiv, Ukraine
Dnipro Hlinky 2, of. 1003, 49000, Dnipro, Ukraine
Email info@syndicode.com
Phone (+1) 9035021111