com.github.tonivade.purefun.monad.Reader Maven / Gradle / Ivy
/*
* Copyright (c) 2018-2019, Antonio Gabriel Muñoz Conejo
* Distributed under the terms of the MIT License
*/
package com.github.tonivade.purefun.monad;
import com.github.tonivade.purefun.Function1;
import com.github.tonivade.purefun.HigherKind;
@HigherKind
@FunctionalInterface
public interface Reader {
A eval(R reader);
default Reader map(Function1 mapper) {
return reader -> mapper.apply(eval(reader));
}
default Reader flatMap(Function1> mapper) {
return reader -> mapper.apply(eval(reader)).eval(reader);
}
default Reader andThen(Reader next) {
return flatMap(ignore -> next);
}
static Reader pure(A value) {
return reader -> value;
}
static Reader reader(Function1 run) {
return run::apply;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy