Tinkoff/utils.js

Opt-in for currying utils

Chudesnov opened this issue · 6 comments

From README.md:

Most of the utilities are automatically curried

Auto-currying may be very convenient for those who already get it, but it also may be extremely confusing for newcomers (curried functions and higher-order functions in general are harder to use, let alone debug or build new code using them). We could transpile using a custom babel plugin and cut out curry() calls where appropriate (from top-level exports at least) by default, and let people opt-in using a different entry point.

I propose that we either implement the following schema using paths:

import map from '@tinkoff/utils/object/map' // requires all args

import mapR from '@tinkoff/utils/R/object/map' // auto-curried
// or
import mapR from '@tinkoff/utils/object/map/R' // auto-curried

or named exports

import default as map, {R as mapR } from '@tinkoff/utils/object/map' // for auto-curried exports

"Autocurrying" means that utilities are curryied on-demand and can be used as "normal" non-curried functions.

can be used as "normal" non-curried functions.

this leads to unexpected results when invoked with an insufficient number of arguments.

Also this sophistic answer of yours doesn't solve the problem of increased difficulty of debugging curried functions.

What result is expected when invoking a function with an insufficient number of arguments?

Setting the rest of them to default (or undefined if there's no default). That's already done for some utils, but it takes time to find out where it is and where it isn't.

Default arguments are no less unexpected IMO.
Why would you call object/map without second argument? What would you expect when calling object/filter without second argument?
Autocurrying is quite explicit and predictable, especially when you know that every single function in the library is autocurried.

Default arguments are no less unexpected

There's a large difference though: they are a part of ES spec.

This discussion is moving away from my intended goal of making things simpler and into bikeshedding. Let's close it for now and revive if / when more people feel like it's necessary.