Friday, March 24, 2023

Reduce to Dashboard

vintage sausage grinder

When developers use DataWeave, they often come to rely on the reduce() function to fill in any gaps left by the standard Core library. Although filter() and joinBy() and splitBy() and even groupBy() could be implemented by simply using reduce(), we favor the Core library functions as the best implementation of those patterns.

On the other hand, polishing your reduce() game will get you through tight spots sometimes when the requirement is idiosyncratic, or when the standard function just won't do.

So we'll take a data set that represents a crude inventory, and use reduce() to extract a dashboard snapshot showing projected revenue, and potential growth through untapped inventory.

(BTW, if more about DataWeave is not your cup of tea, never fear. We are talking about the onset of automation in the workplace next. So drop by again.)

Monday, February 13, 2023

Just the Good Bits


Sometimes you find a use case that has a simple and elegant solution in a particular programming language. It might come from a question in conversation, or a requirement in a project on the table. The nature of elegance in code defies firm definition, but as a famous Jurist once said, "I can't define it, but I do know what I like."

One characteristic I usually find in what most observers might call "elegant code" is brevity. Fewer lines of code mean fewer places for a software fault to lurk. DataWeave certainly lends itself to brevity, even nearly to the point of compulsion.

Recently, a student of mine raised a question after doing one of the standard exercises in the MuleSoft Developer series using DataWeave. His question surfaced a typical use case for an API. 

We had just finished a Walkthrough that has us observe how to filter the elements of an Object given a list of desired fields.

His idea was to allow a query parameter that listed the fields being requested. If an API interface enumerates the fields that may be requested, the input can be easily validated.

Once we walked through the idea, we ended with a single line of code that completely handled the task. Follow our logic, and see if you find the outcome to be elegant, or simply brief.

Friday, January 13, 2023

Everyone's New Best Friend

 Everywhere I go, people are talking about OpenAI ChatGPT. They don't evangelize, they just mention it with a wink and a smile. Of COURSE you know all about this charming chat bot. And that's why we're smiling.

I had to get a look as soon as I heard about it from this NY Times article. It didn't take long before some of the responses passed my own personal Turing Test

I soon found myself arguing with the bot, struggling to get it to reconsider its answer. I was arguing with an algorithm! 

And given the nascent and experimental nature of my new friend, I would swear that I saw it evolve, day to day. (Stick with me to the end, and I'll entertain you with my own idiot glee by arguing with someone who is not there. Or is it arguing with someone who WAS there, but not actually someone?)

Reduce to Dashboard

When developers use DataWeave, they often come to rely on the reduce() function to fill in any gaps left by the standard Core library. Altho...