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

com.github.tonivade.zeromock.api.RequestHandlerK Maven / Gradle / Ivy

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

import com.github.tonivade.purefun.Function1;
import com.github.tonivade.purefun.Kind;
import com.github.tonivade.purefun.Witness;
import com.github.tonivade.purefun.typeclasses.Monad;

@FunctionalInterface
public interface RequestHandlerK extends Function1> {

  default RequestHandlerK preHandle(Monad monad, PreFilterK before) {
    return request ->
        monad.flatMap(before.apply(request), either -> either.fold(monad::pure, this::apply));
  }

  default RequestHandlerK postHandle(Monad monad, PostFilterK after) {
    return andThen(value -> monad.flatMap(value, after))::apply;
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy