public abstract class Next<M,F>
extends java.lang.Object
Update
function.
Upon calling an Update function with an Event and Model, a Next object will be returned that contains the new Model (if there is one) and Effect objects that describe which side-effects should take place.
Modifier | Constructor and Description |
---|---|
protected |
Next() |
Modifier and Type | Method and Description |
---|---|
static <M,F> Next<M,F> |
dispatch(java.util.Set<? extends F> effects)
Create a Next that doesn't update the model but dispatches the supplied effects.
|
abstract java.util.Set<F> |
effects()
Get the effects of this Next.
|
boolean |
hasEffects()
Check if this Next contains effects.
|
boolean |
hasModel()
Check if this Next contains a model.
|
void |
ifHasModel(Consumer<M> consumer)
If the model is present, call the given consumer with it, otherwise do nothing.
|
protected abstract M |
model()
Get the model of this Next, if it has one.
|
M |
modelOrElse(M fallbackModel)
Try to get the model from this Next, with a fallback if there isn't one.
|
M |
modelUnsafe()
Get the model of this Next.
|
static <M,F> Next<M,F> |
next(M model)
Create a Next that updates the model but dispatches no effects.
|
static <M,F> Next<M,F> |
next(M model,
java.util.Set<? extends F> effects)
Create a Next that updates the model and dispatches the supplied set of effects.
|
static <M,F> Next<M,F> |
noChange()
Create an empty Next that doesn't update the model or dispatch effects.
|
@Nullable protected abstract M model()
public final boolean hasModel()
@Nonnull public abstract java.util.Set<F> effects()
Will return an empty set if there are no effects.
public final boolean hasEffects()
@Nonnull public M modelOrElse(M fallbackModel)
fallbackModel
- the default model to use if the Next doesn't have a model@Nonnull public M modelUnsafe()
In almost all cases you should use modelOrElse(M)
or ifHasModel(com.spotify.mobius.functions.Consumer<M>)
instead.
java.util.NoSuchElementException
- if this Next has no modelpublic void ifHasModel(Consumer<M> consumer)
@Nonnull public static <M,F> Next<M,F> next(M model, java.util.Set<? extends F> effects)
@Nonnull public static <M,F> Next<M,F> next(M model)
@Nonnull public static <M,F> Next<M,F> dispatch(java.util.Set<? extends F> effects)
@Nonnull public static <M,F> Next<M,F> noChange()