'Updated comments;'
This commit is contained in:
parent
b54d5336f2
commit
96a395a6e3
@ -25,11 +25,15 @@ public class ImperativeVsDeclarative {
|
||||
.mapToInt(e -> e * 2) // Closure
|
||||
.sum());
|
||||
|
||||
// 1. Lambda expressions: A Lambda expression is an anonymous method that has mutability at very minimum and it has only a parameter list and a body.
|
||||
// 1. Lambda expressions: A Lambda expression is an anonymous method
|
||||
// that has mutability at very minimum and it has only a parameter
|
||||
// list and a body.
|
||||
|
||||
// 2. in the above code of declarative style, every function is a pure function and pure functions don’t have side effects.
|
||||
// 2. in the above code of declarative style, every function is a
|
||||
// pure function and pure functions don’t have side effects.
|
||||
|
||||
// 3. lambdas are stateless and closure has immutable state. It means in any circumstances, the closure could not be mutable.
|
||||
// 3. lambdas are stateless and closure has immutable state. It means
|
||||
// in any circumstances, the closure could not be mutable.
|
||||
}
|
||||
|
||||
public static void immutable() {
|
||||
@ -55,8 +59,10 @@ public class ImperativeVsDeclarative {
|
||||
// factor = 3;// uncomment this
|
||||
|
||||
// * the variable factor is by default being considered as final.
|
||||
// * we should never try mutating any variable which is used inside pure functions == that would violate pure functions rules
|
||||
// which says pure function should neither change anything nor depend on anything that changes
|
||||
// * we should never try mutating any variable which is used inside
|
||||
// pure functions == that would violate pure functions rules
|
||||
// which says pure function should neither change anything nor
|
||||
// depend on anything that changes
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
Loading…
Reference in New Issue
Block a user