Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3283494
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T20:02:53+00:00 2026-05-17T20:02:53+00:00

Following obviously works, but I do not like to wrap items in Tuple, ImmutableMap<String,

  • 0

Following obviously works, but I do not like to wrap items in Tuple,

    ImmutableMap<String, Function<Tuple2<Double>, Double>> op = new //
    ImmutableMap.Builder<String, Function<Tuple2<Double>, Double>>()
            .put("+", new Function<Tuple2<Double>, Double>() {
                @Override public Double apply(Tuple2<Double> data) {
                    return data.Val_1 + data.Val_2;
                }
            }).build();
    System.out.println(op.get("+").apply(new Tuple2<Double>(3d, 4d)));

I want to write something like:

    ImmutableMap<String, Function<Double[], Double>> op = new //
    ImmutableMap.Builder<String, Function<Double[], Double>>()
            .put("+", new Function<Double[], Double>() {
                @Override
                public Double apply(Double... data) {
                    return data[0] + data[1];
                }
            }).build();
    System.out.println(op.get("+").apply(3d, 4d));

Help would be most useful, ty.

Edit: Problem solved, started using:

public interface T2Function<T> {
    T apply(T Val_1, T Val_2);
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T20:02:54+00:00Added an answer on May 17, 2026 at 8:02 pm

    I think you’d be better off using an interface of your own, something like this:

    public interface Operation {
      double apply(double a, double b);
    }
    

    Guava’s Function is a single argument function and not really appropriate for anything multi-argument.

    Another thing I’ve experimented with is a ReduceFunction<F, T> that happens to be usable for such a thing. It’s for use with the reduce or fold operation and looks something like:

    public interface ReduceFunction<F, T> {
      T apply(T a, F b); // I can't decide on good names for the parameters =(
    }
    

    This lets you do things like

    List<Double> doubles = ...
    Double sum = reduce(doubles, MathOps.add(), 0.0);
    

    where MathOps.add() is a ReduceFunction<Double, Double> that does the obvious thing.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am new to C++ programming and am obviously missing something. In the following
I'm new to VisualForce, as you will obviously recognize by the following. How would
I'm new in C# but not new to coding --being doing it for almost
I am new to both Python (and django) - but not to programming. I
Background: Suppose I have the following obviously-incorrect PHP: try{ $vtest = ''; print(array_pop($vtest)); }catch(Exception
Following code produces a nested array as a result for keys containing three items:
Following code takes like 2500 milliseconds on an i7-*3.4 GHz windows-7 64-bit computer to
I have an interface which is used like the following: if (SUCCEEDED(pInterface->GetSize(&size)) { wchar_t
I start the Windows On-Screen-Keyboard like that: s_onScreenKeyboard = new Process(); s_onScreenKeyboard.StartInfo = new
I have a 2-dimensional array of objects (predominantly, but not exclusively strings) that I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.