yangxu998 / guava-libraries

Automatically exported from code.google.com/p/guava-libraries
Apache License 2.0
0 stars 0 forks source link

Request a Function that returns the apply() results of another Function within strategy pattern #633

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
I often require a Function that returns the apply() results of another Function 
within strategy pattern.

I make strategy Function this way :
Function<V, Function<V, R>> strategy = Functions.forMap(ImmutableMap.of(value1, 
function1, value2, function2), defaultFunction);

but I would like to use a Function<V, R> inside client code, so I end to make 
this result function as a wrapper around the strategy function :

class ResultFunction<F, T> implements Function<F, T> {
    public ResultFunction(Function<F, Function<F, T>> f) {
        this.f = f;
    }

    @Override
    public T apply(F input) {
        return this.f.apply(input).apply(input);
    }

    private final Function<F, Function<F, T>> f;
}

May be related to issue 562.

Does this need may end in Functions class ? I not sure about the ResultFunction 
name. Maybe StrategyResult.

Original issue reported on code.google.com by amer...@gmail.com on 24 May 2011 at 3:58

GoogleCodeExporter commented 9 years ago
I can't imagine this would have a wide audience. It's also trivial for users 
who need it to implement it themselves.

Original comment by kevinb@google.com on 25 May 2011 at 6:56

GoogleCodeExporter commented 9 years ago
This issue has been migrated to GitHub.

It can be found at https://github.com/google/guava/issues/<id>

Original comment by cgdecker@google.com on 1 Nov 2014 at 4:15

GoogleCodeExporter commented 9 years ago

Original comment by cgdecker@google.com on 3 Nov 2014 at 9:09