Git Product home page Git Product logo

arraync's People

Contributors

hacklone avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

arraync's Issues

Polyfill?

Correct me if I'm wrong, but as far as I can tell, there is no proposal for adding async functions to the array prototype, is there? If that's the case as I suspect, calling this library a polyfill is misleading. Also, editing the prototype of built-in types (such as the Array object) is highly discouraged these days as it risks clashes with future standards and other libraries. I suggest you change your library so it uses a new custom array type instead of adding extra methods to the prototype of the native Array. Here's an example using the ES2015 class syntax:

class AsyncArray extends Array {

    constructor(…args) { super(…args); } // Apparently, this super call is necessary for built-in types

    // Your extra async functions
}

How does filter work?

This is my code -

'use strict';

const arraync = require('arraync');

function greaterThan3(num){
   return new Promise(function(resolve, reject){
   	setTimeout(function(){
   		resolve(num > 3);
   	}, 1000);
   });
}

var numbers = [1,2,3,4,5];

(async()=>{
   const ans = await numbers.filterAsync(await greaterThan3Async);
   console.log(ans);
})();

I'm trying to filter the array using an async function but this is what I get as output -

[ false, false, false, true, true ]

Also I get this same output when I use mapAsync instead of filterAsync.

How do I get the output -

[4, 5]

import 'arraync' adds async function names to array properties

When I import the code using import 'arraync' in typescript, it permanently adds all async array function names to any array props resulting in the following when I try to iterate an array using a for...in-loop in js:

var a = [1,2,3]; for(var item in a) console.log(item);

results in:
image


This causes a lot of problems for me, because accessing elements using the index is always broken. Is there a quick fix for this without searching the whole transpiled code? ;)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.