diff options
| author | Ben Culkin <scorpress@gmail.com> | 2020-12-03 19:21:38 -0500 |
|---|---|---|
| committer | Ben Culkin <scorpress@gmail.com> | 2020-12-03 19:21:38 -0500 |
| commit | 0a8f34c27c6ef93c5c94d17728af62c7607e225f (patch) | |
| tree | 3bbbbb6d62649c7411e7ae3d53a75786255ed84e /src/main/java/bjc/data/IHolder.java | |
| parent | 097a33bc2ecaa64a664550ddd62ccd8de47c51d0 (diff) | |
Rename types to match Java style
This renames several interfaces that had names like IWhatever, since
that isn't a style that Java uses
Diffstat (limited to 'src/main/java/bjc/data/IHolder.java')
| -rw-r--r-- | src/main/java/bjc/data/IHolder.java | 177 |
1 files changed, 0 insertions, 177 deletions
diff --git a/src/main/java/bjc/data/IHolder.java b/src/main/java/bjc/data/IHolder.java deleted file mode 100644 index e0d39aa..0000000 --- a/src/main/java/bjc/data/IHolder.java +++ /dev/null @@ -1,177 +0,0 @@ -package bjc.data; - -import java.util.function.Consumer; -import java.util.function.Function; -import java.util.function.UnaryOperator; - -import bjc.data.internals.BoundListHolder; -import bjc.data.internals.WrappedLazy; -import bjc.data.internals.WrappedOption; -import bjc.funcdata.FunctionalList; -import bjc.funcdata.theory.Functor; - -/** - * A holder of a single value. - * - * @author ben - * - * @param <ContainedType> - * The type of value held. - */ -public interface IHolder<ContainedType> extends Functor<ContainedType> { - /** - * Bind a function across the value in this container. - * - * @param <BoundType> - * The type of value in this container. - * - * @param binder - * The function to bind to the value. - * - * @return A holder from binding the value. - */ - public <BoundType> IHolder<BoundType> - bind(Function<ContainedType, IHolder<BoundType>> binder); - - /** - * Apply an action to the value. - * - * @param action - * The action to apply to the value. - */ - public default void doWith(final Consumer<? super ContainedType> action) { - transform(value -> { - action.accept(value); - - return value; - }); - } - - @Override - default <ArgType, ReturnType> Function<Functor<ArgType>, Functor<ReturnType>> - fmap(final Function<ArgType, ReturnType> func) { - return argumentFunctor -> { - if (!(argumentFunctor instanceof IHolder<?>)) { - final String msg - = "This functor only supports mapping over instances of IHolder"; - - throw new IllegalArgumentException(msg); - } - - final IHolder<ArgType> holder = (IHolder<ArgType>) argumentFunctor; - - return holder.map(func); - }; - } - - @Override - public default ContainedType getValue() { - return unwrap(value -> value); - } - - /** - * Lifts a function to bind over this holder. - * - * @param <NewType> - * The type of the functions return. - * - * @param func - * The function to lift over the holder. - * - * @return The function lifted over the holder. - */ - public <NewType> Function<ContainedType, IHolder<NewType>> - lift(Function<ContainedType, NewType> func); - - /** - * Make this holder lazy. - * - * @return A lazy version of this holder. - */ - public default IHolder<ContainedType> makeLazy() { - return new WrappedLazy<>(this); - } - - /** - * Make this holder a list. - * - * @return A list version of this holder. - */ - public default IHolder<ContainedType> makeList() { - return new BoundListHolder<>(new FunctionalList<>(this)); - } - - /** - * Make this holder optional. - * - * @return An optional version of this holder. - */ - public default IHolder<ContainedType> makeOptional() { - return new WrappedOption<>(this); - } - - /** - * Create a new holder with a mapped version of the value in this holder. - * - * Does not change the internal state of this holder. - * - * @param <MappedType> - * The type of the mapped value. - * - * @param mapper - * The function to do mapping with. - * - * @return A holder with the mapped value - */ - public <MappedType> IHolder<MappedType> - map(Function<ContainedType, MappedType> mapper); - - /** - * Replace the held value with a new one. - * - * @param newValue - * The value to hold instead. - * - * @return The holder itself. - */ - public default IHolder<ContainedType> replace(final ContainedType newValue) { - return transform(oldValue -> newValue); - } - - /** - * Transform the value held in this holder. - * - * @param transformer - * The function to transform the value with. - * - * @return The holder itself, for easy chaining. - */ - public IHolder<ContainedType> transform(UnaryOperator<ContainedType> transformer); - - /** - * Unwrap the value contained in this holder so that it is no longer held. - * - * @param <UnwrappedType> - * The type of the unwrapped value. - * - * @param unwrapper - * The function to use to unwrap the value. - * - * @return The unwrapped held value. - */ - public <UnwrappedType> UnwrappedType - unwrap(Function<ContainedType, UnwrappedType> unwrapper); - - /** - * Create an instace of IHolder containing a single value. - * - * @param <ElementType> The type of the value contained. - * - * @param contained The value to contain. - * - * @return An instance of IHolder containing that value. - */ - static <ElementType> IHolder<ElementType> of(ElementType contained) { - return new Identity<>(contained); - } -} |
