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

com.github.tonivade.purefun.Consumer1 Maven / Gradle / Ivy

/*
 * Copyright (c) 2018-2021, Antonio Gabriel Muñoz Conejo 
 * Distributed under the terms of the MIT License
 */
package com.github.tonivade.purefun;

import static com.github.tonivade.purefun.Unit.unit;

/**
 * 

This interface represents a function that receives a single parameter but it doesn't generate any result.

*

It's like a {@code Function1}

* @param the type of parameter received by the function */ @FunctionalInterface public interface Consumer1 extends Recoverable { default void accept(A value) { try { run(value); } catch (Throwable t) { sneakyThrow(t); } } void run(A value) throws Throwable; default Function1 asFunction() { return value -> { accept(value); return unit(); }; } default Consumer1 andThen(Consumer1 after) { return value -> { accept(value); after.accept(value); }; } default Function1 peek() { return value -> { accept(value); return value; }; } @SuppressWarnings("unchecked") static Consumer1 of(Consumer1 reference) { return (Consumer1) reference; } static Consumer1 noop() { return value -> { /* noop */ }; } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy