Rebellious, Irrational, Untamed. I make softwares, and things that help making them. Sometimes I pen my musings. 22.
Mar 20, 2023 • 7 tweets • 3 min read
I made a runtime type checker and here's why I think it's cool...npm.im/@sthir/runtime…
I'll also compare it with zod where applicable as it seems to be the most popular solution and my TL keeps hyping it.
1. Negligible Size
baseline: 137B
sthir: 1250B (×9 bigger, 1750B without tree-shaking)
zod: 10570B (×77 bigger, same without tree-shaking)
Mar 19, 2022 • 4 tweets • 1 min read
Interviewer: Map an array
Me: xs.flatMap(x => [f(x)])
Interviewer: Ugh okay... How about filtering an array
Me: xs.flatMap(x => f(x) ? [x] : [])
Me: xs.flatMap((x, i) =>
0 <= i && i <= n - 1 ? [x] :
n <= i && i <= n + m ? []
i === n + m + 1 ? [a, x] :
[x]
)
Jan 3, 2022 • 14 tweets • 6 min read
🎁 New Year's Gift for Y'all
❓ `@sthir/predicate` — An eDSL to write typed predicates
🧙🏻♂️ Write your logical expression in a JS-like eDSL and get the typed predicate inferred.
🔗
👇🏻 Let me explain...github.com/devanshj/sthir…
We often write predicates, for example while filtering an array. But its type (as in `x is NarrowedX`) doesn't get inferred...