proposal-flatMap | proposal for flatten and flatMap on arrays | Functional Programming library

 by   tc39 HTML Version: Current License: No License

kandi X-RAY | proposal-flatMap Summary

kandi X-RAY | proposal-flatMap Summary

proposal-flatMap is a HTML library typically used in Programming Style, Functional Programming applications. proposal-flatMap has no bugs, it has no vulnerabilities and it has low support. You can download it from GitHub.

A proposal to add Array.prototype.flat (formerly known as Array.prototype.flatten) and Array.prototype.flatMap to ECMAScript.
Support
    Quality
      Security
        License
          Reuse

            kandi-support Support

              proposal-flatMap has a low active ecosystem.
              It has 214 star(s) with 19 fork(s). There are 172 watchers for this library.
              OutlinedDot
              It had no major release in the last 6 months.
              There are 1 open issues and 46 have been closed. On average issues are closed in 187 days. There are no pull requests.
              It has a neutral sentiment in the developer community.
              The latest version of proposal-flatMap is current.

            kandi-Quality Quality

              proposal-flatMap has no bugs reported.

            kandi-Security Security

              proposal-flatMap has no vulnerabilities reported, and its dependent libraries have no vulnerabilities reported.

            kandi-License License

              proposal-flatMap does not have a standard license declared.
              Check the repository for any license declaration and review the terms closely.
              OutlinedDot
              Without a license, all rights are reserved, and you cannot use the library in your applications.

            kandi-Reuse Reuse

              proposal-flatMap releases are not available. You will need to build from source code and install.

            Top functions reviewed by kandi - BETA

            kandi's functional review helps you automatically verify the functionalities of the libraries and avoid rework.
            Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of proposal-flatMap
            Get all kandi verified functions for this library.

            proposal-flatMap Key Features

            No Key Features are available at this moment for proposal-flatMap.

            proposal-flatMap Examples and Code Snippets

            No Code Snippets are available at this moment for proposal-flatMap.

            Community Discussions

            Trending Discussions on proposal-flatMap

            QUESTION

            Is js native array.flat slow for depth=1?
            Asked 2020-May-22 at 06:29

            This gist is a small benchmark I wrote comparing the performance for 4 alternatives for flattening arrays of depth=1 in JS (the code can be copied as-is into the google console). If I'm not missing anything, the native Array.prototype.flat has the worst performance by far - on the order of 30-50 times slower than any of the alternatives.

            Update: I've created a benchmark on jsperf.

            It should be noted that the 4th implementation in this benchmark is consistently the most performant - often achieving a performance that is 70 times better. The code was tested several times in node v12 and the Chrome console.

            This result is accentuated most in a large subset - see the last 2 arrays tested below. This result is very surprising, given the spec, and the V8 implementation which seems to follow the spec by the letter. My C++ knowledge is non-existent, as is my familiarity with the V8 rabbit hole, but it seems to me that given the recursive definition, once we reach a final depth subarray, no further recursive calls are made for that subarray call (the flag shouldFlatten is false when the decremented depth reaches 0, i.e., the final sub-level) and adding to the flattened result includes iterative looping over each sub-element, and a simple call to this method. Therefore, I cannot see a good reason why a.flat should suffer so much on performance.

            I thought perhaps the fact that in the native flat the result's size isn't pre-allocated might explain the difference. The second implementation in this benchmark, which isn't pre-allocated, shows that this alone cannot explain the difference - it is still 5-10 times more performant than the native flat. What could be the reason for this?

            Implementations tested (order is the same in code, stored in the implementations array - the two I wrote are at the end of code snippet):

            1. My own flattening implementation that includes pre-allocating the final flattened length (thus avoiding size all re-allocations). Excuse the imperative style code, I was going for max performance.
            2. Simplest naive implementation, looping over each sub-array and pushing into the final array. (thus risking many size re-allocations).
            3. Array.prototype.flat (native flat)
            4. [ ].concat(...arr) (=spreading array, then concatenating the results together. This is a popular way of accomplishing a depth=1 flattening).

            Arrays tested (order is the same in code, stored in the benchmarks object):

            1. 1000 subarrays with 10 elements each. (10 thou total)
            2. 10 subarrays with 1000 elements each. (10 thou total)
            3. 10000 subarrays with 1000 elements each. (10 mil total)
            4. 100 subarrays with 100000 elements each. (10 mil total)

            ...

            ANSWER

            Answered 2020-Apr-24 at 20:16

            (V8 developer here.)

            The key point is that the implementation of Array.prototype.flat that you found is not at all optimized. As you observe, it follows the spec almost to the letter -- that's how you get an implementation that's correct but slow. (Actually the verdict on performance is not that simple: there are advantages to this implementation technique, like reliable performance from the first invocation, regardless of type feedback.)

            Optimizing means adding additional fast paths that take various shortcuts when possible. That work hasn't been done yet for .flat(). It has been done for .concat(), for which V8 has a highly complex, super optimized implementation, which is why that approach is so stunningly fast.

            The two handwritten methods you provided get to make assumptions that the generic .flat() has to check for (they know that they're iterating over arrays, they know that all elements are present, they know that the depth is 1), so they need to perform significantly fewer checks. Being JavaScript, they also (eventually) benefit from V8's optimizing compiler. (The fact that they get optimized after some time is part of the explanation why their performance appears somewhat variable at first; in a more robust test you could actually observe that effect quite clearly.)

            All that said, in most real applications you probably won't notice a difference in practice: most applications don't spend their time flattening arrays with millions of elements, and for small arrays (tens, hundreds, or thousands of elements) the differences are below the noise level.

            Source https://stackoverflow.com/questions/61411776

            Community Discussions, Code Snippets contain sources that include Stack Exchange Network

            Vulnerabilities

            No vulnerabilities reported

            Install proposal-flatMap

            You can download it from GitHub.

            Support

            For any new features, suggestions and bugs create an issue on GitHub. If you have any questions check and ask questions on community page Stack Overflow .
            Find more information at:

            Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items

            Find more libraries
            CLONE
          • HTTPS

            https://github.com/tc39/proposal-flatMap.git

          • CLI

            gh repo clone tc39/proposal-flatMap

          • sshUrl

            git@github.com:tc39/proposal-flatMap.git

          • Stay Updated

            Subscribe to our newsletter for trending solutions and developer bootcamps

            Agree to Sign up and Terms & Conditions

            Share this Page

            share link