6.3 Predefined Functional Interfaces Flashcards
ποΈ What is a Function?
A Function is a Functional Interface whose S.A.M βapplyβ takes a Generic argument and returns a Generic value
ποΈ What is the SAM signature of the pre-defined functional interface Function?
Function :: R apply(T t);
ποΈ What methods do take a generic argument and return a generic value?
o Collection -> toArray(..)
o Optional -> map()|flatMap()
o Stream -> map()|flatMap()
reduce()|toArray()
o Map -> compute+(If{Absent|Present)
merge()|replaceAll()
o Comparator -> comparing()|thenComparing()
ποΈ What is a Consumer?
A Consumer is a Functional Interface whose S.A.M takes a Generic argument and returns nothing
ποΈ What is the SAM signature of the pre-defined functional interface Consumer?
Consumer :: void accept(T t);
ποΈ What methods do take a generic argument and donβt return anything ?
o Collection -> forEach()
o Optional -> ifPresent()|ifPresentOrElse()
o Stream -> collect()|forEach()|forEachOrdered|peek()
o Map -> forEach()
ποΈ What is a Supplier?
A Supplier is a functional interface whose S.A.M takes NO argument and returns a generic value.
ποΈ What is the SAM signature of the pre-defined functional interface Supplier?
Supplier :: T get();
ποΈ What methods donβt take any argument and return a generic value ?
o Math -> random()
o Optional -> orElseGet()|orElseThrow()
o Objects.requireNonNull()
o CompletableFuture.supplyAsync()
ποΈ What is a Predicate?
A Predicate is Functional Interface whose S.A.M takes a Generic argument and returns a boolean.
ποΈ What is the SAM signature of the pre-defined functional interface Predicate?
Predicate :: boolean test(T t);
ποΈ What methods do take a generic argument and return boolean ?
o Collection -> removeIf(..)
o Optional -> filter(..)
o Stream -> filter
{none|any|all}Match
iterate|dropWhile|takeWhile
o Collectors -> filtering|partitioningBy*