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

jio.DebuggerHelper Maven / Gradle / Ivy

The newest version!
package jio;

import java.util.List;
import java.util.function.Supplier;
import java.util.stream.IntStream;

final class DebuggerHelper {

  static  Supplier> debugSupplier(final Supplier> supplier,
                                                     final String expName,
                                                     final String context
                                                    ) {
    return () -> debugIO(supplier.get(),
                         expName,
                         context
                        );

  }

  static  List> debugLambdas(List> lambdas,
                                                                  String expName,
                                                                  String context
                                                                 ) {
    return IntStream.range(0,
                           lambdas.size())
                    .mapToObj(i -> debugLambda(lambdas.get(i),
                                               String.format("%s[%s]",
                                                             expName,
                                                             i
                                                            ),
                                               context
                                              ))
                    .toList();
  }

  static  Lambda debugLambda(Lambda lambda,
                                                           String expName,
                                                           String context
                                                          ) {
    return lambda
        .map(it -> debugIO(it,
                           expName,
                           context
                          )
            );
  }

  static  List>> debugSuppliers(List>> suppliers,
                                                            String expName,
                                                            String context
                                                           ) {
    return IntStream.range(0,
                           suppliers.size())
                    .mapToObj(i -> debugSupplier(suppliers.get(i),
                                                 String.format("%s[%s]",
                                                               expName,
                                                               i
                                                              ),
                                                 context
                                                )
                             )
                    .toList();
  }

  static List> debugConditions(final List> exps,
                                           final EventBuilder eventBuilder
                                          ) {
    return IntStream.range(0,
                           exps.size())
                    .mapToObj(i -> debugIO(exps.get(i),
                                           "%s[%d]".formatted(eventBuilder.exp,
                                                              i),
                                           eventBuilder.context
                                          ))
                    .toList();
  }

  static  IO debugIO(final IO io,
                                     final String expName,
                                     final String context
                                    ) {
    return debugExp(io,
                    EventBuilder.of(expName,
                                    context));
  }

  static  IO debugExp(IO o,
                                      EventBuilder builder
                                     ) {
    return o instanceof Exp exp ? exp.debugEach(builder) : o.debug(builder);

  }

  static  List> debugList(List> list,
                                             String expName,
                                             String context
                                            ) {
    return IntStream.range(0,
                           list.size())
                    .mapToObj(i -> debugIO(list.get(i),
                                           String.format("%s[%s]",
                                                         expName,
                                                         i
                                                        ),
                                           context
                                          )
                             )
                    .toList();
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy