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

com.github.tonivade.zeromock.server.ResponseInterpreterK Maven / Gradle / Ivy

The newest version!
/*
 * Copyright (c) 2018-2024, Antonio Gabriel Muñoz Conejo 
 * Distributed under the terms of the MIT License
 */
package com.github.tonivade.zeromock.server;

import com.github.tonivade.purefun.Kind;
import com.github.tonivade.purefun.concurrent.Future;
import com.github.tonivade.purefun.concurrent.FutureOf;
import com.github.tonivade.purefun.concurrent.Promise;
import com.github.tonivade.purefun.core.Producer;
import com.github.tonivade.purefun.effect.UIO;
import com.github.tonivade.purefun.effect.UIOOf;
import com.github.tonivade.purefun.effect.URIO;
import com.github.tonivade.purefun.effect.URIOOf;
import com.github.tonivade.purefun.monad.IO;
import com.github.tonivade.purefun.monad.IOOf;
import com.github.tonivade.purefun.type.Id;
import com.github.tonivade.purefun.type.IdOf;
import com.github.tonivade.zeromock.api.HttpResponse;

@FunctionalInterface
public interface ResponseInterpreterK> {

  Promise run(Kind response);

  static ResponseInterpreterK> io() {
    return response -> response.fix(IOOf::toIO).runAsync().toPromise();
  }

  static ResponseInterpreterK> uio() {
    return response -> response.fix(UIOOf::toUIO).runAsync().toPromise();
  }

  static  ResponseInterpreterK> urio(Producer env) {
    return response -> response.fix(URIOOf::toURIO).runAsync(env.get()).toPromise();
  }

  static ResponseInterpreterK> sync() {
    return response -> Promise.make().succeeded(response.fix(IdOf::toId).value());
  }

  static ResponseInterpreterK> async() {
    return response -> response.fix(FutureOf::toFuture).toPromise();
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy