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

org.aya.util.IterableUtil Maven / Gradle / Ivy

There is a newer version: 0.34.0
Show newest version
// Copyright (c) 2020-2024 Tesla (Yinsen) Zhang.
// Use of this source code is governed by the MIT license that can be found in the LICENSE.md file.
package org.aya.util;

import org.jetbrains.annotations.NotNull;

import java.util.function.BiConsumer;
import java.util.function.Consumer;

public interface IterableUtil {
  static  void forEach(@NotNull Iterable it, @NotNull BiConsumer separator, @NotNull Consumer run) {
    var iter = it.iterator();
    if (!iter.hasNext()) return;
    var last = iter.next();
    run.accept(last);

    while (iter.hasNext()) {
      var now = iter.next();
      separator.accept(last, now);
      run.accept(now);
      last = now;
    }
  }

  static  void forEach(@NotNull Iterable it, @NotNull Runnable separator, @NotNull Consumer run) {
    forEach(it, (_, _) -> separator.run(), run);
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy