Updeep, Remeda edition

January 2nd, 2023

Updeep, Remeda edition

I am to give a mini-talk about TypeScript in a fortnight, so the moment seems propice to return to a TypeScript project and see where I currently stand in my forever hot latin relationship with that uptight super-set of JavaScript. For that warm-up session, I needed something small and standalonish, so I decided to revisit Updeep.

In case you don’t already know about it, Updeep is an awesome small package that provides wickedly succinct ways to do deep update to data structures. For full-on typed goodness, immer is probably better, but updeep has that o so alluringly dangerous razor-sharp edge. For example, need to update a bunch of customer data for the new year? Easy peasy:

import u from "updeep";

let peeps = [
  { name: "yanick", activeYear: "2022", subscriptionCost: 20 },
  { name: "yenzie", activeYear: "2022", subscriptionCost: 43 },

peeps = u.map(
    activeYear: "2023",
    subscriptionCost: (cost) => cost + 10, // inflation baby

Updeep already comes with TypeScript definitions (the original patch for it being from your truly, dating from one of the previous times I wanted to experiment with TypeScript), but I was curious to see how it would look like if written in TS from scratch. And since I was going to be elbow-deep in code guts, I thought it might be fun to change its dependency from lodash to remeda.

Why that change of library? Well, lodash is wonderfully comprehensive, but it has two things going against it: it’s not playing well wit tree shaking (so that wonderfully comprehensiveness unfortunately also get to be a rather heavy ball and chain), and its development is gathering dust. Fortunately, the number of young contenders competing to fill the same niche is great, and of the lot remeda is my current favorite. Relatively small, yet reasonably comprehensive, with all the functional programming and currying trimming that I like.

All that to say, a new fork of updeep lives. I didn’t tweak the documentation yet, but it’s mostly compatible with the real Updeep. The big difference being that I adopted the way remeda curries its functions:

// original updeep
const dataIn = { a: 1, b: 2 };

let dataOut = u({ c: 3 }, dataIn); // simple call
dataOut = u({ c: 3 })(dataIn); // curried

// updeep-remeda
dataOut = u(dataIn, { c: 3 }); // simple call
dataOut = u({ c: 3 })(dataIn); // curried

That is, the curried forms are the same, but in the simple case updeep-remeda asks for the input data first, rather than to have it tagged on at the end.

And… yeah, that’s it. If there is a demand for it, I might fine-tune the TypeScript types, update the documentation, and actually publish this fork. We’ll see…