Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

compactJoin #304

Open
Undistraction opened this issue Jan 22, 2018 · 3 comments
Open

compactJoin #304

Undistraction opened this issue Jan 22, 2018 · 3 comments

Comments

@Undistraction
Copy link
Collaborator

Undistraction commented Jan 22, 2018

Is your feature request related to a problem? Please describe.
Returns a string made by inserting the separator between each element and concatenating all the elements into a single string. Before the concatenation happens, the values as compacted using using RA.compact.

Describe the solution you'd like

RA.compactJoin(', ' ['a', '', 'b', null, 'c', undefined, 'd']); //=> 'a, b, c, d'

Describe alternatives you've considered

ad-hoc composition

Additional context
Original issue description:
join currently joins all values, even if undefined (or NaN, or null). How about a safe version that rejects undefined values before joining? Perhaps it could follow the same blacklist as compact, or could allow the blacklist to be configured.

const joinWithComma = join(',')
joinWithComma([1, undefined,]) // '1,'

const safeJoin = s => compose(join(s), reject(isUndefined))
const safeJoinWithComma = safeJoin(',')
safeJoinWithComma([1, undefined, 2]) // '1,2'

REPL

@char0n
Copy link
Owner

char0n commented Feb 1, 2018

We have already discussed about safe* functions with @guillaumearm in #38 (comment). I think these kind of functions may hide nasty errors because items from the array are implicitly lost before transformation. But safe doesn't tell us anything about this filtering. I can imagine having compactJoin, but would have to see more real world usecases and support for this. For more than 5 years I don't remember having to need something like this, because before I return from function I compact the result of the function and then pass it to higher levels of the app where join can transform them to string.

@Undistraction
Copy link
Collaborator Author

I would argue that is is just a way of being defensive if you don't entirely trust the values you want to joint, but I agree compactJoin is a better name. I'll leave open for now and try and dig up a usecase that will convince you.

@Undistraction Undistraction changed the title safeJoin / compactJoin compactJoin Feb 1, 2018
@guillaumearm
Copy link
Collaborator

Personally, I often write a compactJoin function for making my webpack or rollup configuration like this :

const configuration = {
  ...,
  plugins: compactJoin([
    isProduction ? uglifyPlugin : undefined,
    ...,
  ])
  ...,
}

I use it to conditionally concat things.
IMHO, this is definitively a feature.

@char0n char0n added the Hacktoberfest Hacktoberfest 2020 label Sep 13, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants