summaryrefslogtreecommitdiff
path: root/BJC-Utils2/src/main/java/bjc/utils/data/IHolder.java
blob: ddcb2f64365807d02b58c05389a9a3838feedb26 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package bjc.utils.data;

import java.util.function.Consumer;
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
	 */
	public <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
	 */
	public 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
	 */
	public <E> E unwrap(Function<T, E> f);

	/**
	 * Call a provided function with the value being held
	 * 
	 * @param f
	 *            The function to call
	 */
	public void doWith(Consumer<T> f);
}