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 Block
A block of code.Similar to
Runnable
, but allows throwing of checked exceptions.
-
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description default Action<Object>
action()
Creates anAction
from this block, where the argument is ignored.void
execute()
Execute the action.default <T> T
map(Function<? super Block,? extends T> function)
Maps a block onto a new object with the provided function.static Block
noop()
static Block
throwException(Throwable throwable)
Returns an action that immediately throws the given exception.default Runnable
toRunnable()
Converts this action to a runnable.
-
-
-
Method Detail
-
noop
static Block noop()
-
throwException
static Block throwException(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 Runnable toRunnable()
Converts this action to a runnable.Any thrown exceptions will be
unchecked
.- Returns:
- a runnable
-
action
default Action<Object> action()
Creates anAction
from 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
-
-