com.github.tonivade.purefun.instances.ControlInstances Maven / Gradle / Ivy
/*
* Copyright (c) 2018-2022, Antonio Gabriel Muñoz Conejo
* Distributed under the terms of the MIT License
*/
package com.github.tonivade.purefun.instances;
import static com.github.tonivade.purefun.control.ControlOf.toControl;
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 super T, ? extends Kind> map) {
return value.fix(toControl()).flatMap(map.andThen(ControlOf::narrowK));
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy