These are chat archives for ramda/ramda

21st
Feb 2019
Rakesh Pai
@rakeshpai
Feb 21 03:03

Just for kicks, I decided to give TS a spin in a large-ish JS codebase. I expected errors all over the place just because such things happen. But I couldn't fix the errors.compose and pipe confuse the type-checker, and I have pipe all over my code. "Expected 0 arguments, got 1 instead."

PS: In case you didn't know, you can very easily get static typechecking for your JS files (!) without having to convert it to TS. If you're using VSCode, you don't even need to install anything. Just set "javascript.implicitProjectConfig.checkJs": true in your settings. If you're not on VSCode, you'll can use the typescript compiler with the --checkJsflag. You don't need to make any changes to your code. You can later add additional type information if you want, using JSDoc comments. Details here.

Rakesh Pai
@rakeshpai
Feb 21 03:18
IMHO, TS does have its benefits, and we shouldn't minimize it. For example, 'Union Types' come pretty close to satisfying the use-cases of sum-type ADTs + pattern matching + exhaustiveness checking. --strictNullChecks come pretty close to satisfying the use-cases of the Maybe monad. Sure, they aren't as elegant as the corresponding FP solutions to these problems, but they're strictly enforced, which I'd argue is more valuable. Also, the intellisense you get with TS in VSCode (and I'm sure elsewhere) is just awesome. You won't need to ever again switch to another file to see what the arguments of that function are, or what are the keys on that object.
Rakesh Pai
@rakeshpai
Feb 21 03:30
To contextualize, I don't think TS will add lots of value when you're on a small maybe 2-people team, with a small codebase. But as the team the code grows, and it becomes impossible to keep the code in your head, having the editor tell you when you're wrong as you're typing is super valuable. Never letting you make (a certain class of) mistakes. And the help you get when making large refactoring changes has to be experienced to be appreciated.
Jonah
@jonahx
Feb 21 06:07
I want to consider an array of boolean values as a bit mask representing an int. Can we do better than:
// [bool] => int
const toInt = R.pipe(
  R.map(x => x ? '1' : '0'),
  R.join(''),
  x => parseInt(x, 2)
)

lg(toInt([true, false, true])) // => 5
pentatronix
@pentatronix
Feb 21 06:36
@jonahx Perhaps actual bitfields: https://emergent.systems/blog/bit-fields/
pentatronix
@pentatronix
Feb 21 06:42
What's everyones preffered implmentation of maybe and either etc? Monet.js? And why isn't it part of the core Ramda?
Markus
@evdama
Feb 21 11:43
Markus
@evdama
Feb 21 11:54
@rakeshpai good point
I just had a look at the ts roadmap and found something interesting Microsoft/TypeScript#5453
Brad Compton (he/him)
@Bradcomp
Feb 21 16:19
@pentatronix I have been using Crocks lately for its ADTs and I dig it. Good ergonomics and a wide variety of types
Ben Briggs
@ben-eb
Feb 21 18:22
@pentatronix See ramda/ramda#683
pentatronix
@pentatronix
Feb 21 20:10
@Bradcomp Thanks! This looks like a well thought out and thorough library
@ben-eb - Yes this is definitely a useful thread, and convoluted. Thanks :)
Ben Briggs
@ben-eb
Feb 21 20:21
@pentatronix You're welcome :)