net.sf.staccatocommons.lang.function
Class Functions

java.lang.Object
  extended by net.sf.staccatocommons.lang.function.Functions

public class Functions
extends Object

Class factory methods for some common Functions

Author:
flbulgarelli

Method Summary
static
<A,B> net.sf.staccatocommons.defs.function.Function<A,B>
constant(B value)
          Returns a function that takes one argument, and regardless of it, returns a given value.
static
<A,B> net.sf.staccatocommons.defs.function.Function<A,B>
constant(net.sf.staccatocommons.defs.Thunk<B> thunk)
          Returns a function that takes one argument, and regadless of it, returns the given thunk's value.
static
<A,B> net.sf.staccatocommons.defs.function.Function<A,B>
from(net.sf.staccatocommons.defs.Applicable<? super A,? extends B> applicable)
          Converts the given Applicable into a Function by casting it, is possible, or creating a new function that delegates its apply method to it.
static
<A,B,C> net.sf.staccatocommons.defs.function.Function2<A,B,C>
from(net.sf.staccatocommons.defs.Applicable2<? super A,? super B,? extends C> applicable)
          Converts the given Applicable2 into a Function2 by casting it, is possible, or creating a new function that delegates its apply method to it.
static
<A> net.sf.staccatocommons.defs.function.Function<A,A>
identity()
          Returns the identity function, that is, a Function that takes an argument and returns it.
static
<A> net.sf.staccatocommons.defs.function.Function<A,A>
impure(net.sf.staccatocommons.defs.Executable<? super A> block)
          Answers an impure - with side effect - function that executes the given block and answers its argument
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

from

@NonNull
public static <A,B> net.sf.staccatocommons.defs.function.Function<A,B> from(@NonNull
                                                                                    net.sf.staccatocommons.defs.Applicable<? super A,? extends B> applicable)
Converts the given Applicable into a Function by casting it, is possible, or creating a new function that delegates its apply method to it.

Type Parameters:
A -
B -
Parameters:
applicable - the Applicable to convert
Returns:
new a function that applies the given Applicable, if it is not already a Function, or the given applicable casted to Function, otherwise

from

@NonNull
public static <A,B,C> net.sf.staccatocommons.defs.function.Function2<A,B,C> from(@NonNull
                                                                                         net.sf.staccatocommons.defs.Applicable2<? super A,? super B,? extends C> applicable)
Converts the given Applicable2 into a Function2 by casting it, is possible, or creating a new function that delegates its apply method to it.

Type Parameters:
A -
B -
C -
Parameters:
applicable - the Applicable to convert
Returns:
new a function that applies the given Applicable2, if it is not already a Function2, or the given applicable casted to Function2, otherwise

identity

@Constant
public static <A> net.sf.staccatocommons.defs.function.Function<A,A> identity()
Returns the identity function, that is, a Function that takes an argument and returns it. This functions grants to be Transparent

Type Parameters:
A -
Returns:
the constant identity function

constant

@NonNull
public static <A,B> net.sf.staccatocommons.defs.function.Function<A,B> constant(B value)
Returns a function that takes one argument, and regardless of it, returns a given value. This function grants to be Transparent and Constant

Type Parameters:
A -
B -
Parameters:
value - the value the function will return when applied
Returns:
a new function

constant

@NonNull
public static <A,B> net.sf.staccatocommons.defs.function.Function<A,B> constant(@NonNull
                                                                                        net.sf.staccatocommons.defs.Thunk<B> thunk)
Returns a function that takes one argument, and regadless of it, returns the given thunk's value.

This function grants to be Transparent and Constant only as long as the given thunk is transparent too. As a consequence, passing a non-transparent Thunk may be effective, but counterintuitive, as the resulting function would be impure and not constant at all.

Type Parameters:
A -
B -
Parameters:
thunk -
Returns:
a new function

impure

public static <A> net.sf.staccatocommons.defs.function.Function<A,A> impure(@NonNull
                                                                            net.sf.staccatocommons.defs.Executable<? super A> block)
Answers an impure - with side effect - function that executes the given block and answers its argument

Type Parameters:
A -
Parameters:
block - the block to wrap
Returns:
a new, impure, function.


Copyright © 2010-2012 Staccatocommons. All Rights Reserved.