Jewell brings Higher-Order Messaging to Javascript Jewell — Javascript Syntax Sugar for Higher-Order Messaging If you want to jump straight to the action (GitHub repo), click here . I've worked and played with many languages and frameworks throughout my career and learned a lot with each one of them. Recently I've been exploring Javascript quite a lot and, one day, while working with arrays I remembered a very cool feature that the Laravel Framework has, called higher-order messaging. It allows you to create very expressive 1 liners, such as: (PHP code) $employees->filter->retired->each->sendPayment(); With some research I found that there are also some implementations of this using Ruby, one of my favorite languages. Ruby's syntax is very fluid, so higher-order messaging looks very natural to it. Using , here's how the same code would look like in Ruby. Nat Pryce's implementation employees.where.retired?.do.sendPayment() What about Javascript? As you may know, that are quite many Javascript packages out there, so guess what was my reaction once I researched and realized there was no higher-order messaging library for Javascript? ¯\_(ツ)_/¯ If you know a library that does that, please leave it on the comments below, I’d love to check it out. I honestly couldn’t find it on NPM/Google Since I couldn't find a library that allowed me to accomplish that same behavior, I wanted to see if that was even possible. I started hacking a version in my spare time and turns out it could be done with one of ES6’s features, Proxy! \o/ The tricky part was getting the syntax to be pretty and to make sense in the Javascript ecosystem without creating a monster. After a few iterations, I finally got a version that I was happy with! This is how it looks like: employees.filter.retired.forEach.sendPayment(); Pretty similar to the example I showed you above, huh?!? Let's see a full code sample now, step by step. Add Jewell to your project Step 0. npm install jewell --save Import and apply it to the class, so we can use higher-order messaging with native array methods. Step 1. jewellPrototype Array Declare a class. In our case it's Diamond Step 2. Create an array of Diamonds Step 3. Have fun Step 4. Notice that in our example we call , that's because is a function. If that's the case, why do we not call it here? Get all blue diamonds #isBlue #isBlue diamonds.filter.isBlue.forEach.buy() The answer is: you can, but it's not necessary. Since has no arguments, Jewell assumes it should be invoked to allow the chaining. isBlue Besides the class itself, you can also use Jewell with your own library that has shortcuts to manipulating arrays or individual instances. jewelling Array Keep in mind that Jewell replaces the original method with a Proxy, so before shipping it to production, make sure you’re not creating some crazy behaviors in your app or slowing everything down. ⚠ Warning: You can check out more examples . If you have any questions please leave a comment bellow or open an issue on the repo. You're also very welcome to contribute with Pull Requests and suggestions. in the repo With no further ado, here's the GitHub repo: _jewell - Javascript Syntax Sugar for Higher-Order Messaging_github.com pedsmoreira/jewell Extra If you’re into pieces of software crafted with love, I'd like to invite you to . Come and get your own rockstar portfolio 🤘. GitShowcase cc Victor F. Santos _Developer, feature your best projects in a plug and play portfolio. The best part, for free._www.gitshowcase.com GitShowcase