... when @types/ramda
is installed.
const curried = add(1);
// infers: const curried: (b: number) => number
...
/* | |
Find a 5 digit combination that meets these constraints: | |
x[0] * x[1] == 24 | |
x[3] == x[1] / 3 | |
x[3] + x[4] == x[0] + x[2] | |
sum(x) == 26 | |
not all the digits are unique | |
*/ | |
/* |
// TL:DR | |
// In JS (and most other languages using floating point) | |
// 0.3 - 0.2 != 0.1 | |
// 0.6 + 0.3 != 0.9 | |
// These might cause problems for you. | |
// But! | |
// (0.3 * 10) - (0.2 * 10) == 0.1 * 10 == 1 | |
// (0.6 * 10) + (0.3 * 10) == 0.9 * 10 == 9 | |
// Use this to your advantage. | |
// For example, if your get inputs in numbers representing ££.pp, multiply by 100 and do your maths in pennies. |
I love Ramda, but my organisation is falling away from it - we have hires who don't think in FP, and Typescript and Ramda fight somewhat.
You can coax Ramda code to work in Typescript by strategically adding as
in the right places. But it's often quite
hard work -- harder work than refactoring away from Ramda before converting the plain JS to TS.
Here's some patterns for refactoring away from Ramda. In most cases, applying any of these changes leaves you with less clear code than you started with. But you can now apply more refactorings - extract function, extract method, pulling up
#!/usr/bin/env node | |
/* | |
My problem is that I have two networks - one in my house and one in my garden office, and I move | |
between them. In the office, my Mac can still see the house network, so it doesn't automatically switch | |
to the office network. It's strong enough for many things, but not for video conferencing. So unless I | |
remember to manually switch networks, I end up noticing when my colleagues tell me I'm breaking up. | |
This script exits early if we're on a network that isn't part of that scenario. |
Speed and cost.
We are testing a function that takes a function as an argument. We don't need Jest to do its magic poke-in-replacements-for-imports magic. But we have the option of using jest.fn() to create a test double.
Example is in plain JS so that types don't clutter things.
Code under test (CUT):