Remix.run Logo
the-grump 8 days ago

You can express the loop as a list comprehension, and I would too.

As for the logic, I would still use pattern matching for branching and destructuring, but I’d put it in a helper. More lines is not a negative in my book, though I admit the thing with convert and format is weird.

pansa2 8 days ago | parent | next [-]

> I would still use pattern matching for branching and destructing, but I’d put it in a helper

Yeah, using a helper function makes things much clearer. To be honest though, I'm not a huge fan of using either `isinstance` (which is generally a sign of a bad design) nor `match/case` (which is essentially a "modern" way to write `isinstance`).

I can't help but think that a better design could avoid the need for either of those (e.g. via polymorphism).

the-grump 8 days ago | parent | next [-]

What I would use is an ADT and I make a wish for that every day in every language that’s not Haskell :D

Haskell also has operator overloading on steroids so you could use the (|>) operator from Flow and write transformations the same as you would shell pipes. I’d love to whip up an example but it’s difficult on this tiny screen. Will try to remember when I’m on my computer.

Before someone chimes in with ML propaganda, I warn you that I’m going to exercise my rights under the Castle Doctorine the moment you say “of”.

davepeck 8 days ago | parent | prev [-]

You can access .strings and .interpolations directly and avoid type checks. There is always one more string than interpolation, of which there may be zero.

zahlman 8 days ago | parent | prev [-]

> As for the logic, I would still use pattern matching for branching and destructuring, but I’d put it in a helper.

I wrote it up (https://news.ycombinator.com/item?id=43650001) before reading your comment :)