Package ratpack.func
Interface Block
-
- Functional Interface:
- This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
@FunctionalInterface public interface BlockA block of code.Similar to
Runnable, but allows throwing of checked exceptions.
-
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Default Methods Deprecated Methods Modifier and Type Method Description default Action<java.lang.Object>action()Creates anActionfrom this block, where the argument is ignored.voidexecute()Execute the action.default <T> Tmap(Function<? super Block,? extends T> function)Maps a block onto a new object with the provided function.static Blocknoop()default Operationoperation()Deprecated.since 1.5static BlockthrowException(java.lang.Throwable throwable)Returns an action that immediately throws the given exception.default java.lang.RunnabletoRunnable()Converts this action to a runnable.
-
-
-
Method Detail
-
noop
static Block noop()
-
execute
void execute() throws java.lang.ExceptionExecute the action.- Throws:
java.lang.Exception- any
-
throwException
static Block throwException(java.lang.Throwable throwable)
Returns an action that immediately throws the given exception.The exception is thrown via
Exceptions.toException(Throwable)- Parameters:
throwable- the throwable to immediately throw when the returned action is executed- Returns:
- an action that immediately throws the given exception.
-
toRunnable
default java.lang.Runnable toRunnable()
Converts this action to a runnable.Any thrown exceptions will be
unchecked.- Returns:
- a runnable
-
operation
@Deprecated default Operation operation()
Deprecated.since 1.5Creates anOperationfrom this block.- Returns:
- an operation
- See Also:
Operation.of(Block)
-
action
default Action<java.lang.Object> action()
Creates anActionfrom this block, where the argument is ignored.- Returns:
- an action that executes this block
- Since:
- 1.1
-
map
default <T> T map(Function<? super Block,? extends T> function)
Maps a block onto a new object with the provided function.The block is not implicitly handled and the mapping function must call
execute()if desired.- Type Parameters:
T- the return type- Parameters:
function- the mapping function- Returns:
- the mapped block
-
-