Top Description Constructors Methods
org.eclipse.xtext.xbase.lib

public Class FunctionExtensions

extends Object
Class Inheritance
Annotations
@GwtCompatible
Imports
org.eclipse.xtext.xbase.lib.Functions.Function0, .Functions.Function1, .Functions.Function2, .Functions.Function3, .Functions.Function4, .Functions.Function5, .Functions.Function6, .Procedures.Procedure0, .Procedures.Procedure1, com.google.common.annotations.GwtCompatible

This is an extension library for functions, e.g. closures.
Author
Sven Efftinge - Initial contribution and API
See Also
Functions

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public static <
the type of input to the before function, and to the composed function
V
,
the type of output of the before function, and input to the after function
T
,
the type of output to the after function, and to the composed function
R
>
Functions.Function1<V, R>

Returns:

a composed function that first applies the before function and then applies the after function
andThen
(final Functions.Function1<? super V, ? extends T>
the function to apply before the after function is applied
before
,
final Functions.Function1<? super T, ? extends R>
the function to apply after the before function is applied
after
)

Returns a composed function that first applies the before function to its input, and then applies the after function to the result.

public static <
the type of the first parameter to the before function, and to the composed function
V1
,
the type of the second parameter to the before function, and to the composed function
V2
,
the type of output of the before function, and input to the after function
T
,
the type of output to the after function, and to the composed function
R
>
Functions.Function2<V1, V2, R>

Returns:

a composed function that first applies the before function and then applies the after function
andThen
(final Functions.Function2<? super V1, ? super V2, ? extends T>
the function to apply before the after function is applied
before
,
final Functions.Function1<? super T, ? extends R>
the function to apply after the before function is applied
after
)

Returns a composed function that first applies the before function to its input, and then applies the after function to the result.

public static <
the type of input for the before operation
T
>
Procedures.Procedure1<T>

Returns:

a composed Procedure1 that performs in sequence the before operation followed by the after operation
andThen
(final Procedures.Procedure1<? super T>
the operation to perform first
before
,
final Procedures.Procedure1<? super T>
the operation to perform afterwards
after
)

Returns a composed Procedure1 that performs, in sequence, the before operation followed by the after operation.

public static Procedures.Procedure0

Returns:

a composed Procedure1 that performs in sequence the before operation followed by the after operation
andThen
(final Procedures.Procedure0
the operation to perform first
before
,
final Procedures.Procedure0
the operation to perform afterwards
after
)

Returns a composed Procedure1 that performs, in sequence, the before operation followed by the after operation.

public static <
the type of input to the before function, and to the composed function
V
,
the type of output of the before function, and input to the after function
T
,
the type of output to the after function, and to the composed function
R
>
Functions.Function1<V, R>

Returns:

a composed function that first applies the before function and then applies the after function
compose
(final Functions.Function1<? super T, ? extends R>
the function to apply after the before function is applied
after
,
final Functions.Function1<? super V, ? extends T>
the function to apply before the after function is applied
before
)

Returns a composed function that first applies the before function to its input, and then applies the after function to the result.

public static <P1, RESULT> Functions.Function0<RESULT>

Returns:

a function that takes no arguments. Never null.
curry
(final Functions.Function1<? super P1, ? extends RESULT>
the original function. May not be null.
function
,
final P1
the fixed argument.
argument
)

Curries a function that takes one argument.

public static <P1, P2, RESULT> Functions.Function1<P2, RESULT>

Returns:

a function that takes one argument. Never null.
curry
(final Functions.Function2<? super P1, ? super P2, ? extends RESULT>
the original function. May not be null.
function
,
final P1
the fixed first argument of function.
argument
)

Curries a function that takes two arguments.

public static <P1, P2, P3, RESULT> Functions.Function2<P2, P3, RESULT>

Returns:

a function that takes two arguments. Never null.
curry
(final Functions.Function3<? super P1, ? super P2, ? super P3, ? extends RESULT>
the original function. May not be null.
function
,
final P1
the fixed first argument of function.
argument
)

Curries a function that takes three arguments.

public static <P1, P2, P3, P4, RESULT> Functions.Function3<P2, P3, P4, RESULT>

Returns:

a function that takes three arguments. Never null.
curry
(final Functions.Function4<? super P1, ? super P2, ? super P3, ? super P4, ? extends RESULT>
the original function. May not be null.
function
,
final P1
the fixed first argument of function.
argument
)

Curries a function that takes four arguments.

public static <P1, P2, P3, P4, P5, RESULT> Functions.Function4<P2, P3, P4, P5, RESULT>

Returns:

a function that takes four arguments. Never null.
curry
(final Functions.Function5<? super P1, ? super P2, ? super P3, ? super P4, ? super P5, ? extends RESULT>
the original function. May not be null.
function
,
final P1
the fixed first argument of function.
argument
)

Curries a function that takes five arguments.

public static <P1, P2, P3, P4, P5, P6, RESULT> Functions.Function5<P2, P3, P4, P5, P6, RESULT>

Returns:

a function that takes five arguments. Never null.
curry
(final Functions.Function6<? super P1, ? super P2, ? super P3, ? super P4, ? super P5, ? super P6, ? extends RESULT>
the original function. May not be null.
function
,
final P1
the fixed first argument of function.
argument
)

Curries a function that takes six arguments.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

FunctionExtensionsback to summary
public FunctionExtensions()

Method Detail

andThenback to summary
public static <V, T, R> Functions.Function1<V, R> andThen(final Functions.Function1<? super V, ? extends T> before, final Functions.Function1<? super T, ? extends R> after)

Returns a composed function that first applies the before function to its input, and then applies the after function to the result. If evaluation of either function throws an exception, it is relayed to the caller of the composed function.

Parameters
<V>
the type of input to the before function, and to the composed function
<T>
the type of output of the before function, and input to the after function
<R>
the type of output to the after function, and to the composed function
before:Functions.Function1<? super V, ? extends T>

the function to apply before the after function is applied

after:Functions.Function1<? super T, ? extends R>

the function to apply after the before function is applied

Returns:Functions.Function1<V, R>

a composed function that first applies the before function and then applies the after function

Exceptions
NullPointerException:
if before or after is null
Since
2.9
See Also
compose(Functions.Function1, Functions.Function1)
andThenback to summary
public static <V1, V2, T, R> Functions.Function2<V1, V2, R> andThen(final Functions.Function2<? super V1, ? super V2, ? extends T> before, final Functions.Function1<? super T, ? extends R> after)

Returns a composed function that first applies the before function to its input, and then applies the after function to the result. If evaluation of either function throws an exception, it is relayed to the caller of the composed function.

Parameters
<V1>
the type of the first parameter to the before function, and to the composed function
<V2>
the type of the second parameter to the before function, and to the composed function
<T>
the type of output of the before function, and input to the after function
<R>
the type of output to the after function, and to the composed function
before:Functions.Function2<? super V1, ? super V2, ? extends T>

the function to apply before the after function is applied

after:Functions.Function1<? super T, ? extends R>

the function to apply after the before function is applied

Returns:Functions.Function2<V1, V2, R>

a composed function that first applies the before function and then applies the after function

Exceptions
NullPointerException:
if before or after is null
Since
2.9
See Also
compose(Functions.Function1, Functions.Function1)
andThenback to summary
public static <T> Procedures.Procedure1<T> andThen(final Procedures.Procedure1<? super T> before, final Procedures.Procedure1<? super T> after)

Returns a composed Procedure1 that performs, in sequence, the before operation followed by the after operation. If performing either operation throws an exception, it is relayed to the caller of the composed operation. If performing the before operation throws an exception, the after operation will not be performed.

Parameters
<T>
the type of input for the before operation
before:Procedures.Procedure1<? super T>

the operation to perform first

after:Procedures.Procedure1<? super T>

the operation to perform afterwards

Returns:Procedures.Procedure1<T>

a composed Procedure1 that performs in sequence the before operation followed by the after operation

Exceptions
NullPointerException:
if before or after is null
Since
2.9
andThenback to summary
public static Procedures.Procedure0 andThen(final Procedures.Procedure0 before, final Procedures.Procedure0 after)

Returns a composed Procedure1 that performs, in sequence, the before operation followed by the after operation. If performing either operation throws an exception, it is relayed to the caller of the composed operation. If performing the before operation throws an exception, the after operation will not be performed.

Parameters
before:Procedures.Procedure0

the operation to perform first

after:Procedures.Procedure0

the operation to perform afterwards

Returns:Procedures.Procedure0

a composed Procedure1 that performs in sequence the before operation followed by the after operation

Exceptions
NullPointerException:
if before or after is null
Since
2.9
composeback to summary
public static <V, T, R> Functions.Function1<V, R> compose(final Functions.Function1<? super T, ? extends R> after, final Functions.Function1<? super V, ? extends T> before)

Returns a composed function that first applies the before function to its input, and then applies the after function to the result. If evaluation of either function throws an exception, it is relayed to the caller of the composed function.

Parameters
<V>
the type of input to the before function, and to the composed function
<T>
the type of output of the before function, and input to the after function
<R>
the type of output to the after function, and to the composed function
after:Functions.Function1<? super T, ? extends R>

the function to apply after the before function is applied

before:Functions.Function1<? super V, ? extends T>

the function to apply before the after function is applied

Returns:Functions.Function1<V, R>

a composed function that first applies the before function and then applies the after function

Exceptions
NullPointerException:
if before or after is null
Since
2.9
See Also
andThen(Functions.Function1, Functions.Function1)
curryback to summary
public static <P1, RESULT> Functions.Function0<RESULT> curry(final Functions.Function1<? super P1, ? extends RESULT> function, final P1 argument)

Curries a function that takes one argument.

Parameters
function:Functions.Function1<? super P1, ? extends RESULT>

the original function. May not be null.

argument:P1

the fixed argument.

Returns:Functions.Function0<RESULT>

a function that takes no arguments. Never null.

Annotations
@Pure
curryback to summary
public static <P1, P2, RESULT> Functions.Function1<P2, RESULT> curry(final Functions.Function2<? super P1, ? super P2, ? extends RESULT> function, final P1 argument)

Curries a function that takes two arguments.

Parameters
function:Functions.Function2<? super P1, ? super P2, ? extends RESULT>

the original function. May not be null.

argument:P1

the fixed first argument of function.

Returns:Functions.Function1<P2, RESULT>

a function that takes one argument. Never null.

Annotations
@Pure
curryback to summary
public static <P1, P2, P3, RESULT> Functions.Function2<P2, P3, RESULT> curry(final Functions.Function3<? super P1, ? super P2, ? super P3, ? extends RESULT> function, final P1 argument)

Curries a function that takes three arguments.

Parameters
function:Functions.Function3<? super P1, ? super P2, ? super P3, ? extends RESULT>

the original function. May not be null.

argument:P1

the fixed first argument of function.

Returns:Functions.Function2<P2, P3, RESULT>

a function that takes two arguments. Never null.

Annotations
@Pure
curryback to summary
public static <P1, P2, P3, P4, RESULT> Functions.Function3<P2, P3, P4, RESULT> curry(final Functions.Function4<? super P1, ? super P2, ? super P3, ? super P4, ? extends RESULT> function, final P1 argument)

Curries a function that takes four arguments.

Parameters
function:Functions.Function4<? super P1, ? super P2, ? super P3, ? super P4, ? extends RESULT>

the original function. May not be null.

argument:P1

the fixed first argument of function.

Returns:Functions.Function3<P2, P3, P4, RESULT>

a function that takes three arguments. Never null.

Annotations
@Pure
curryback to summary
public static <P1, P2, P3, P4, P5, RESULT> Functions.Function4<P2, P3, P4, P5, RESULT> curry(final Functions.Function5<? super P1, ? super P2, ? super P3, ? super P4, ? super P5, ? extends RESULT> function, final P1 argument)

Curries a function that takes five arguments.

Parameters
function:Functions.Function5<? super P1, ? super P2, ? super P3, ? super P4, ? super P5, ? extends RESULT>

the original function. May not be null.

argument:P1

the fixed first argument of function.

Returns:Functions.Function4<P2, P3, P4, P5, RESULT>

a function that takes four arguments. Never null.

Annotations
@Pure
curryback to summary
public static <P1, P2, P3, P4, P5, P6, RESULT> Functions.Function5<P2, P3, P4, P5, P6, RESULT> curry(final Functions.Function6<? super P1, ? super P2, ? super P3, ? super P4, ? super P5, ? super P6, ? extends RESULT> function, final P1 argument)

Curries a function that takes six arguments.

Parameters
function:Functions.Function6<? super P1, ? super P2, ? super P3, ? super P4, ? super P5, ? super P6, ? extends RESULT>

the original function. May not be null.

argument:P1

the fixed first argument of function.

Returns:Functions.Function5<P2, P3, P4, P5, P6, RESULT>

a function that takes five arguments. Never null.

Annotations
@Pure