JSX violates referential transparency
medium.com9 pointsby _davidchambers0 comments
const f1 = function(s) {
let data;
try {
data = JSON.parse(s);
} catch (err) {}
if (data != null &&
data.a != null &&
data.a.b != null &&
typeof data.a.b.c === 'string') {
let x = parseFloat(data.a.b.c);
if (x === x) {
return x;
}
}
return null;
};
const f2 =
R.pipe(S.parseJson,
R.chain(S.gets(['a', 'b', 'c'])),
R.filter(R.is(String)),
R.chain(S.parseFloat),
S.fromMaybe(null));
Note that in the first function we have an unsafe expression, data.a.b.c
which we must guard with null/undefined checks. Unsafe expressions can easily get out of sync with their corresponding guards.
> A full-stack TypeScript CMS built on Astro and Cloudflare. EmDash takes the ideas that made WordPress dominant -- extensibility, admin UX, a plugin ecosystem -- and rebuilds them on serverless, type-safe foundations.
Someone should introduce the authors to the lovely em dash character. It's perfect for such sentences!