1

Happy new year everyone!

I have the following exercise for my Programming courses:

Write a class named Imbauba. Class must contain the following method:

A public method named dit which has a parameter (Function Float, Float type) named dawnward and returns Fuction Float, Float result. Lambda function which is returned must contain the value of dawnward divided by 67

   public class Imbauba {
        public Function<Float, Float> dit(Function<Float, Float> dawnward) {
             Function<Float, Float> sss = (a) -> dawnward / 67F;
             return sss;
        }
   }

This is what I've done so far. I have no clue how to continue. Can anyone guide me close to the solution? Thanks in advance

1 Answer 1

1

You need to call the method on the Function. There is no funky syntaz to call the "function" of a functional interface. Something like:

         Function<Float, Float> sss = (a) -> dawnward.apply(a) / 67F;

@VLAZ mentions andThen in the comments. compose does the same thing in the opposite order. I think they are detrimental to readability, and are only really useful if it avoids creating another lambda expression (and even then I'd prefer not to bother).

Sign up to request clarification or add additional context in comments.

3 Comments

Just for reference - the Function class also has a method called andThen that will perform functional composition with another Function. The equivalent to the above would be Function<Float, Float> sss = dawnward.andThen(x -> x / 67F);
Just curious why do you think that return dawnward.andThen(x -> x / 67F) is detrimental to readability and return (a) -> dawnward.apply(a) / 67F is not?
@Naman It introduces another method. I can never remember which way around those methods work. Far too much extra thinking for me. OTOH, andThen does reduce the size of the lambda and assists in factoring it out.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.