diff options
| author | bculkin2442 <bjculkin@mix.wvu.edu> | 2016-02-29 09:05:36 -0500 |
|---|---|---|
| committer | bculkin2442 <bjculkin@mix.wvu.edu> | 2016-02-29 09:05:36 -0500 |
| commit | a3a95154666eb0fbae948173d13ad72c5509b1c4 (patch) | |
| tree | 6230da28df025803241cea23895d2f1777329ab7 /BJC-Utils2/src/main/java/bjc/utils/data/IHolder.java | |
| parent | c732b309a14696f60100440871c90789d443ad24 (diff) | |
Factored interface out of GenHolder
Diffstat (limited to 'BJC-Utils2/src/main/java/bjc/utils/data/IHolder.java')
| -rw-r--r-- | BJC-Utils2/src/main/java/bjc/utils/data/IHolder.java | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/BJC-Utils2/src/main/java/bjc/utils/data/IHolder.java b/BJC-Utils2/src/main/java/bjc/utils/data/IHolder.java new file mode 100644 index 0000000..aa7d5bd --- /dev/null +++ b/BJC-Utils2/src/main/java/bjc/utils/data/IHolder.java @@ -0,0 +1,45 @@ +package bjc.utils.data; + +import java.util.function.Function; + +/** + * Generic interface for things that store a single value in a roughly + * monadic fashion + * + * @author ben + * + * @param <T> + * The type of data being stored + */ +public interface IHolder<T> { + + /** + * Return the result of applying the given transformation to the held + * value Doesn't change the held value + * + * @param f + * The transformation to apply + * @return A holder with the transformed value + */ + <NewT> IHolder<NewT> map(Function<T, NewT> f); + + /** + * Apply the given transformation to the held value. Returns the holder + * for allowing chaining of transforms + * + * @param f + * The transform to apply to the value + * @return The holder + */ + IHolder<T> transform(Function<T, T> f); + + /** + * Returns a raw mapped value, not contained in a GenHolder + * + * @param f + * The function to use for mapping the value + * @return The mapped value outside of a GenHolder + */ + <E> E unwrap(Function<T, E> f); + +}
\ No newline at end of file |
