diff options
Diffstat (limited to 'src/main/java/bjc/data/internals/WrappedOption.java')
| -rw-r--r-- | src/main/java/bjc/data/internals/WrappedOption.java | 46 |
1 files changed, 27 insertions, 19 deletions
diff --git a/src/main/java/bjc/data/internals/WrappedOption.java b/src/main/java/bjc/data/internals/WrappedOption.java index eb4d120..6becc16 100644 --- a/src/main/java/bjc/data/internals/WrappedOption.java +++ b/src/main/java/bjc/data/internals/WrappedOption.java @@ -11,7 +11,7 @@ import bjc.data.Option; * * @author Ben Culkin. * @param <ContainedType> - * The wrapped type. + * The wrapped type. */ public class WrappedOption<ContainedType> implements IHolder<ContainedType> { /* The held value. */ @@ -21,16 +21,15 @@ public class WrappedOption<ContainedType> implements IHolder<ContainedType> { * Create a new wrapped option. * * @param seedValue - * The value to wrap. + * The value to wrap. */ public WrappedOption(final IHolder<ContainedType> seedValue) { held = new Option<>(seedValue); } /* - * The dummy parameter is to ensure the compiler can pick the right - * method, because without this method erases to the same type as the - * public one. + * The dummy parameter is to ensure the compiler can pick the right method, + * because without this method erases to the same type as the public one. */ private WrappedOption(final IHolder<IHolder<ContainedType>> toHold, @SuppressWarnings("unused") final boolean dummy) { @@ -38,10 +37,12 @@ public class WrappedOption<ContainedType> implements IHolder<ContainedType> { } @Override - public <BoundType> IHolder<BoundType> bind(final Function<ContainedType, IHolder<BoundType>> binder) { - final IHolder<IHolder<BoundType>> newHolder = held.map((containedHolder) -> { + public <BoundType> IHolder<BoundType> + bind(final Function<ContainedType, IHolder<BoundType>> binder) { + final IHolder<IHolder<BoundType>> newHolder = held.map(containedHolder -> { return containedHolder.bind((containedValue) -> { - if(containedValue == null) return new Option<>(null); + if (containedValue == null) + return new Option<>(null); return binder.apply(containedValue); }); @@ -51,17 +52,20 @@ public class WrappedOption<ContainedType> implements IHolder<ContainedType> { } @Override - public <NewType> Function<ContainedType, IHolder<NewType>> lift(final Function<ContainedType, NewType> func) { - return (val) -> { + public <NewType> Function<ContainedType, IHolder<NewType>> + lift(final Function<ContainedType, NewType> func) { + return val -> { return new Option<>(func.apply(val)); }; } @Override - public <MappedType> IHolder<MappedType> map(final Function<ContainedType, MappedType> mapper) { - final IHolder<IHolder<MappedType>> newHolder = held.map((containedHolder) -> { + public <MappedType> IHolder<MappedType> + map(final Function<ContainedType, MappedType> mapper) { + final IHolder<IHolder<MappedType>> newHolder = held.map(containedHolder -> { return containedHolder.map((containedValue) -> { - if(containedValue == null) return null; + if (containedValue == null) + return null; return mapper.apply(containedValue); }); @@ -71,10 +75,12 @@ public class WrappedOption<ContainedType> implements IHolder<ContainedType> { } @Override - public IHolder<ContainedType> transform(final UnaryOperator<ContainedType> transformer) { - held.transform((containedHolder) -> { + public IHolder<ContainedType> + transform(final UnaryOperator<ContainedType> transformer) { + held.transform(containedHolder -> { return containedHolder.transform((containedValue) -> { - if(containedValue == null) return null; + if (containedValue == null) + return null; return transformer.apply(containedValue); }); @@ -84,10 +90,12 @@ public class WrappedOption<ContainedType> implements IHolder<ContainedType> { } @Override - public <UnwrappedType> UnwrappedType unwrap(final Function<ContainedType, UnwrappedType> unwrapper) { - return held.unwrap((containedHolder) -> { + public <UnwrappedType> UnwrappedType + unwrap(final Function<ContainedType, UnwrappedType> unwrapper) { + return held.unwrap(containedHolder -> { return containedHolder.unwrap((containedValue) -> { - if(containedValue == null) return null; + if (containedValue == null) + return null; return unwrapper.apply(containedValue); }); |
