|
|
|
|
|
by another-dave
55 days ago
|
|
> Chaining nudges you toward “process everything,” even when that’s not what you meant to do. It feels pretty clear that the chains in that example (filter/map) are meant for operating on collections. And that if you're searching for a single item then chaining isn't the way to go? Personally, if I knew I wanted only a single item I wouldn't feel more "nudged" towards appending a [0] on the end of a long chain rather than doing a refactor to the find(). As to: data
.transform()
.normalize()
.validate()
.save();
here the problem isn't that you've done method chaining, it's that you've named your functions with terse names that you're going to forget what they do later on e.g. a generic "normalise" vs a "toLowerCase()" or whatever.As apples-to-apples unchained equivalent isn't really any better const transformedData = transform(data);
const normalisedData = normalise(transformedData);
const validatedData = validate(normlisedData);
save(validatedData);
Is not more readable or understandable |
|