Uploaded image for project: 'Commons Collections'
  1. Commons Collections
  2. COLLECTIONS-795

provide a PairIterator to zip two iterators of different types.

Attach filesAttach ScreenshotAdd voteVotersWatch issueWatchersCreate sub-taskLinkCloneUpdate Comment AuthorReplace String in CommentUpdate Comment VisibilityDelete Comments
    XMLWordPrintableJSON

Details

    • New Feature
    • Status: Open
    • Minor
    • Resolution: Unresolved
    • None
    • None
    • Iterator
    • None

    Description

      ZippingIterator provides a way to simulatenously iterate over multiple iterators of the same-type.

      The proposed pair iterator allows simultaneously iterating over two iterators of different type, like the example below:

      Iterator<L> leftIterator =  ...;
      Iterator<R> rightIterator = ...;
      
      PairIterator<L,R> pairIterator = PairIterator.of(leftIterator, rightIterator);
      
      while (pairIterator.hasNext()) {
         ImmutablePair<L,R> item = pairIterator.next();
         ...
      }

       

      Another convenience could be to use an Iterable for easy for-each constructs.

      List<Integer> studentIds = ...
      List<String> studentNames = ...
      
      for (PairedItem<Integer, String> items : IterableUtils.pairedIterable(studentIds, studentNames) {
        Integer studentId = item.getLeft();
        String studentName = item.getRight();
        ...
      }
      
      

       

      Attachments

        Activity

          This comment will be Viewable by All Users Viewable by All Users
          Cancel

          People

            Unassigned Unassigned
            anant.damle Anant Damle

            Dates

              Created:
              Updated:

              Time Tracking

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - 0h
                0h
                Logged:
                Time Spent - 7h 10m
                7h 10m

                Slack

                  Issue deployment