简体   繁体   中英

Functional Programming exercise (Lambda function)

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

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).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM