3 ms·
> Functional code is more readable. There is no way that name: R.pipe(R.prop('name'), R.toUpper), age: R.prop('age'), isAdult: R.always(true) is
by Joker_vD 2y ago
> Functional code is more readable.
There is no way that
name: R.pipe(R.prop('name'), R.toUpper),
age: R.prop('age'),
isAdult: R.always(true)
is more readable than
name: user.name.toUpperCase(),
age: user.age,
isAdult: true
- nine_k 2y agoCertainly so! The first example is needlessly contrived. But instead of for (const i=0; i < data.length; i++) { new_data[i] = old_data[i].toUpperCase(); } you can write const new_data = old_data.map((x) => x.toUpperCase()); I think it's both more clear and less error-prone.
- nuancebydefault 2y agoThe second code does not compile and introduces a new dependency.
- nine_k 2y agoSorry, are we speaking about the same language? https://www.typescriptlang.org/play/?#code/MYewdgzgLgBCA2ATA+oghlNMC8MDaARCAQDQwEBO8AngQLoDcAUKJLGAKYDuqGWuCFOkwA6ALZoADgAppADwCUOAHww5IqCACqkyRwoBhNBA7SFC5i3AQEHEfBABzaZx7C0IgFYgAlmGkE5OYMQA https://www.typescriptlang.org/play/?#code/MYewdgzgLgBCA2ATA...
- nuancebydefault 2y agoMy apologies, I thought it was C++. I should learn typescript, it is one of those I'm postponing.
- Izkata 2y agoNothing in that snippet is Typescript-specific, it's just plain Javascript. All syntactically valid Javascript is also syntactically valid Typescript, it just adds stuff, though you can get runtime errors for things like reassigning variables in a way Javascript is fine with that Typescript disallows.
- kazinator 2y agoBut those are both functional, or can easily be.