Form-based Java Functional Programming (1)

xiaoxiao2021-03-06  37

Note: When you read this article, I hope that you can understand and understand the Java Generic.

Remember: In the weekend, in the FP on the weekend, many people seem to be concerned about FP, and also believe that the role of FP in Java is not big. In fact, this is a big concept error, the development of the model, supports the function of Java's functional programming, and the impact on the functor is very large. Functor will have a lot in terms of algorithm, logic, conditional computation, rule engine, etc., which will be far more. - Estimate the beginning of this, wake up Java developers' re-recognity of FP in Java.

Six Saturday told JavaParty, Functional Programming in Java, but because of it is not prepared, it is not inseparable. Estimate and write some blog to supplement. Of course, in the next day, it is also intended to squeeze the time to delve into the following functor, feel this application, will be very wide in the future, even if Java is an oo language, it is a state-oriented Ordist Programming language.

For Java language, FP is not its special. But Functor is a very good new highlight, although the concept of functor is not new, I have already been raised in C STL: a functor is a function That Can Be Manipulated as an Object, or an Object representing a SINGLE, Generic function. - Through this description, I think we can say this more: functor = function object. So, in the oo language, pure Function does not exist. In the Java language, Function is also an object, this object is functor.

However, in Java, the functor has been supported by Java5's support, and finally broke the ground and became a new highlight. And I also believe that this bright spot will not only be blinking, and will show a bright side in many applications in the future.

Functor is mainly three types of types: predicate, function, process (procedure). The calculation result of the predicate returns only the Boolean value; the calculation calculation of the function returns an object; the process is only responsible for calculation, no return results

Predicate

Return a Boolean Value

FUNCTION

Return an Object Value

Procedure

Don't returniful

Functor itself has a division / binary / three yuan ···. Of course, I am the most common is a dollar (BinnaryPrediCate, binnaryfunction, binnaryprocedure).

The above is some of the abstract concepts, then what is the FUNCTOR looks like?

Let us first let us look at an example. Through this example, let's take a step by step to understand the functor of the functor, what is Functor:

Public Static List SELECT (Collection Source, Unarypredicate Selector) {list Result = New ArrayList ();

For (t item: source) {

IF (selector.test (item)) {

Result.Add (item);

}

}

Return Result;

}

This example is a typical application of the functor, which is constructed with a SELECT algorithm.

(Not finished, to continue tomorrow) WriteD by

Hu Changcheng (Silver Fox 999)

转载请注明原文地址:https://www.9cbs.com/read-71168.html

New Post(0)