-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
1 changed file
with
42 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,44 @@ | ||
### Lambda Master class - part 1 | ||
# FUNCTIONAL INTERFACES @FunctionalInterface: | ||
## Consumer<T>: | ||
|
||
This is the examples used in the talk we made with Stuart Marks (@StuartMarks) at Devoxx Belgium 2018. | ||
|
||
The talk is available on YouTube: https://youtu.be/ePXnCezwRuw and the slides are on Slideshare: https://www.slideshare.net/jpaumard/lambda-and-stream-master-class-part-1 | ||
|
||
You can can see the code exercises without the solutions on this commit: https://github.com/JosePaumard/lambda-master-class-part1/releases/tag/Examples_without_solutions | ||
Recibe un argumento pero no retorna nada. | ||
|
||
- Método funcional: | ||
|
||
void accept(T t); | ||
|
||
- Método default: | ||
|
||
default Consumer<T> andThen(Consumer<T> other) { | ||
return (T t) -> { this.accept(t); other.accept(t);}; | ||
} | ||
|
||
## Predicate<T>: | ||
|
||
Recibe un argumento y retorna un boolean. | ||
|
||
- Método funcional: | ||
|
||
boolean test(T t); | ||
|
||
- Métodos default: | ||
|
||
default Predicate<T> negate() { | ||
return t -> !this.test(t); | ||
} | ||
|
||
default Predicate<T> and(Predicate<T> other) { | ||
Objects.requireNonNull(other); | ||
return t -> this.test(t) && other.test(t); | ||
} | ||
|
||
default Predicate<T> or(Predicate<T> other) { | ||
Objects.requireNonNull(other); | ||
return t -> this.test(t) || other.test(t); | ||
} | ||
|
||
default Predicate<T> isEqual(Object targetRef){ | ||
return (null == targetRef) | ||
? Objects::isNull | ||
: object -> targetRef.equals(object); | ||
} |