30-seconds-of-code: [DESIGN] Flatten and variadic inputs

Created on 30 Dec 2017  路  5Comments  路  Source: 30-seconds/30-seconds-of-code

I've noticed some snippets come in recently that start

const fn = (...arr) => arr = [].concat(...arr), ...

which is a combination of the variadic adapter and a piped flatten before the function.

Should we allow these? While a cool trick, it also leads to a lot of code duplication in snippets.
It's also a situation where

const fn = pipe(fn, flatten, collectInto)

should do the same thing and allow us to keep snippets smaller, less duplicated, and not have every snippet have a confusing footprint of (*|Array<*>|...*) and instead just be one of the three

Now don't get me wrong, the contributions have been great, I'm just curious if we want to duplicate flatten in those snippets or just make them variadic to match with Math.?

Most helpful comment

Tomorrow after work( around 18:00:00 PST ) I'll PR the removal of Math.max and Math.min unless someone beats me to it and resolves this issue. I've been away for the holiday

All 5 comments

Well, turns out that was a pretty bad decision. Your last comment under #295 proves this can go very wrong very fast. Yes, we want developers to handle their own errors and bad input, but this is a bit too far. Keeping everything variadic, without accounting for arrays (not using .concat()) should be ok, provided we add examples that use arrays in combination with the spread operator.

@Chalarangelo In that case, does that make max/min pointless? Since they will no longer accept array inputs

max/min are shim methods that would pipe the input to the Math library for max and min. With adapters those examples are pointless since

const arrayMax = spreadOver(Math.max)
const arrayMin = spreadOver(Math.min)

We could probably change the examples for spreadOver and collectInto to make it a little more clear how it can be used in some situations(promise.all results are awesome for this)

Tomorrow after work( around 18:00:00 PST ) I'll PR the removal of Math.max and Math.min unless someone beats me to it and resolves this issue. I've been away for the holiday

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for any follow-up tasks.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

atomiks picture atomiks  路  6Comments

ecwyne picture ecwyne  路  4Comments

Chalarangelo picture Chalarangelo  路  5Comments

GrosSacASac picture GrosSacASac  路  3Comments

Lucien-X picture Lucien-X  路  5Comments