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.

Please add

map(Func2<? super T, int index, ? extends R> func)

Where the second parameter of Func2 is the index of the element.

A similar overload could be useful on operators like scan, reduce, filter etc.

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:14 (8 by maintainers)

github_iconTop GitHub Comments

29reactions
zsxwingcommented, Feb 1, 2016

By the way, mapWithIndex can be implemented by zipWith(Observable.range(0, Integer.MAX_VALUE)).

9reactions
artem-zinnatullincommented, Jan 31, 2016

Why not use rxjava-extras? 😃

RxJava already has ~4k methods, and it has compose() and some other ways to be extendable.

I’d say, that existing operators are enough to do what you want, though, it’s a little bit less effective than native operator because it creates new Pair each time:

Observable
  .just("a", "b", "c")
  .map(new Func1<String, Pair<Integer, String>>() {
    private int counter; // Or AtomicInteger if needed.

    @Override
    public Pair<Integer, String> call(String s) {
      return new Pair<Integer, String>(counter++, s);
    }
  })

// I have nothing personal against indexed operators, but at the same time I’d vote for keeping API “small”.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Array.prototype.map() - JavaScript - MDN Web Docs
The map() method creates a new array populated with the results of calling a provided function on every element in the calling array....
Read more >
Index inside map() function - javascript - Stack Overflow
The index of the current element being processed in the array. 3) array. The array map was called upon. Share.
Read more >
Index inside map() Function - GeeksforGeeks
The index is used inside map() method to state the position of each element in an array, but it doesn't change the original...
Read more >
JavaScript map index: The Complete Guide - AppDividend
To find an index of the current iterable inside the JavaScript map() function, use the callback function's second parameter. An index used ...
Read more >
How to Use Map Index in JavaScript - Linux Hint
In JavaScript, the map index is considered useful in locating the exact position of an array value, especially in the case of complex...
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