All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.iodesystems.fn.aspects.SizedIterables Maven / Gradle / Ivy

Go to download

Fn is a lazy Java Library that helps utilize some rudimentary functional concepts with more nounular objects

There is a newer version: 3.0.4
Show newest version
package com.iodesystems.fn.aspects;

import com.iodesystems.fn.data.From;
import com.iodesystems.fn.data.From2;
import java.util.Iterator;

public class SizedIterables {

  public static  Iterable of(
      A source, From getSize, From2 getItem) {
    return new Iterable() {
      @Override
      public Iterator iterator() {
        return new Iterator() {
          final int size = getSize.from(source);
          int index = 0;

          @Override
          public boolean hasNext() {
            return index < size;
          }

          @Override
          public B next() {
            return getItem.from(source, index++);
          }
        };
      }
    };
  }
}