purescript-deprecated / purescript-dom

Type definitions and standard effect for interacting with the DOM
41 stars 57 forks source link

Add `toArray` for HTMLCollection #109

Closed i-am-tom closed 7 years ago

i-am-tom commented 7 years ago

With a lot of help from @garyb, here's the toArray for HTMLCollection. It returns the elements within the collection as an Array of Element objects. It was suggested that this be returned as an Unfoldable, but the item function is effectful, so the plan was ruined.

i-am-tom commented 7 years ago

@garyb, with performance in mind, if we can't create an Unfoldable, might it be better to use some more direct JavaScript?

// Convert an HTMLCollection to an Array.
exports.toArray = function (elements) {
  return function () {
    return [].slice.call(elements);
  };
};
garyb commented 7 years ago

Sorry sorry, I'm the worst for leaving this so long!

Yeah, let's just go with the FFI version. I'd usually say the other version is preferrable, but since this is an FFI library anyway, what's one more function in this sea of grossness? :smile:

i-am-tom commented 7 years ago

No worries :) How's it looking now?

garyb commented 7 years ago

Looks good, thanks!