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

flatMap is missing #63

Closed
kay999 opened this issue Feb 26, 2018 · 5 comments
Closed

flatMap is missing #63

kay999 opened this issue Feb 26, 2018 · 5 comments

Comments

@kay999
Copy link

kay999 commented Feb 26, 2018

Why is there no flatMap operation? It's not only very useful, it's also the bind operation for the list monad, so it's kind of heresy to omit it from a "functional" library ;)

There's a "flatten" in rambda, but because it flattens recursively, one can't simply define flatMap as compose(flatten, map).

So please consider adding a non-recursive shallowFlatten and also 'flatMap' (ideally an optimized one, but one based on map and shallowFlatten would also do).

Also a 'scan' operation (similar to reduce but building a list of the result of each iteration instead of giving just the end-result) would be useful (but far less important as flatMap).

Another useful operation would be somethink like "any" which would only test for 'undefined' and return the first non-undefined result of the iteration. This is useful to return the first successful application of a value to some operation (similar to 'find' but returning an arbitrary value instead of the found element).

@selfrefactor
Copy link
Owner

Thanks for opening the issue and your suggestions.

While you explicitly describe your request, it will be much easier for me if you accompany each of them with simple pseudo-code, such as:

const result = R.foo({a: 1, b: '2'}, R.type) 
// result is `['Number', 'String']` 

In general I am open to implement all of your suggestions, but that will have to wait for Typescript 2.8 to arrive(between 1 and 2 months from now).

Then Rambda will switch to Typescript and all of method will be rewritten. During this major change, I will implement all of your suggestions.

I hope you do understand and I will wait for the pseudo-codes.

@davidjbradshaw
Copy link

Why the switch to TypeScript? Surely that will just cut down on the pool of people who could help with the project.

I was just looking at switching to this from Ramda, with the view that I would just implement and contribute any methods that I currently use that are currently missing. If you switch to TypeScript then I think I will just have to fork the project which is a shame.

@selfrefactor selfrefactor reopened this Apr 30, 2018
@selfrefactor
Copy link
Owner

This is big IF for the change to Typescript as we are still waiting for varadic arguments support. That may happen this year maybe not. When it does, it may lead to rewrite but it could lead just to easier to read/write typings file.
So meanwhile feel free to open PR with any useful method that you think it is missing in Rambda.

@thejohnfreeman
Copy link
Contributor

I can help you with some of these functions, but can you answer some questions first? I have read the CONTRIBUTING.md.

  1. It seems like you implement functions twice, in both lib and modules. You have a prepublish command to build lib from modules, but why do you commit it? Do you expect contributors to commit it as well?
  2. It seems like you haven't migrated to TypeScript yet. Is that right?
  3. You have dissoc but no assoc. Is there an assoc under a different name?

I need assoc and flatMap myself.

@selfrefactor
Copy link
Owner

That is very nice of you to help me out.

Here are the answers:

  1. I commit it as it is needed for ES5 support. I don't expect the contributors to run the prepublish command.
  2. No. Still waiting for varadic support landing in Typescript Proposal: Variadic Kinds -- Give specific types to variadic functions microsoft/TypeScript#5453
  3. assoc landed because of someone did a PR. Feel free to add dissoc if you need it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants