com.github.tonivade.purefun.instances.ControlInstances Maven / Gradle / Ivy
/*
* Copyright (c) 2018-2020, Antonio Gabriel Muñoz Conejo
* Distributed under the terms of the MIT License
*/
package com.github.tonivade.purefun.instances;
import com.github.tonivade.purefun.Function1;
import com.github.tonivade.purefun.Kind;
import com.github.tonivade.purefun.control.Control;
import com.github.tonivade.purefun.control.ControlOf;
import com.github.tonivade.purefun.control.Control_;
import com.github.tonivade.purefun.typeclasses.Monad;
public interface ControlInstances {
static Monad monad() {
return ControlMonad.INSTANCE;
}
}
interface ControlMonad extends Monad {
ControlMonad INSTANCE = new ControlMonad() {};
@Override
default Control pure(T value) {
return Control.pure(value);
}
@Override
default Control flatMap(
Kind value, Function1> map) {
return value.fix(ControlOf::narrowK).flatMap(map.andThen(ControlOf::narrowK));
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy