question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Module/Method proposal makeIterable()

See original GitHub issue

@DenisCarriere’s new proposals in #1202 spurred me into starting to write this module, but I’m not having a lot of luck, and I want to talk it over w/ you all because maybe I’m stepping on discussions that you’ve already had.

Simply put, I don’t like turf.featureEach(). I wish there were a way to do something like:

featureCollection = turf.makeIterable(turf.points([[0, 0], ... ]));

var namesArray = featureCollection.map(function(f){ return f.properties.name;});
featureCollection.forEach(function(f){ f.properties.fillColor = "#aa0000"; });
if(featureCollection.length > 100){ console.log("you have a big data set!");};

IIRC, in python, as long as the object responds to two hidden methods, it exposes the object to all of the enumerable methods. It seems like ES6 has something similar w/ Symbol.iterator, if not quite as flexible.

My suggestion then, is having turf.makeIterable() add a bunch of methods to a feature collection so we can use them like arrays. I don’t know if this is a terrible idea, but in writing my modules, I certainly wished feature collections had, at least, map() and filter() methods. I know turf provides turf.featureReduce() in addition to turf.featureEach().

Or would attaching methods to geojson objects cause compatibility problems?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
rowanwinscommented, Dec 26, 2017

-1 from me sorry @muziejus although I understand the sentiment. I don’t think we should be tinkering with the geojson object given that it is a recognised spec, it’s a smidge unintuitive but not really that bad.

0reactions
DenisCarrierecommented, Dec 26, 2017

The intention was good with Symbol.iterator, however we won’t be tinkering with the GeoJSON object.

However we will be eventually adding iterators (apparently it will speed things up), I’ll open a dedicated issue for just that.

Closing this issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

ECMAScript proposal: iterator helpers - 2ality
It introduces utility methods for working with iterable data: .map() , .filter() , .take() , etc. The style of the proposed API clashes...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found