(INDIRA) Call Girl Pune Call Now 8250077686 Pune Escorts 24x7
Â
Kpi driven-java-development
1. KPI driven JAVA(functional) development
Gradual journey from imperative to functional development in JAVA
Anirban Bhattacharjee â Architect @ Walmart Labs
2. About my
functional
exposure
Writing java for
living ⌠since
JDK 4 (mostly
OO way in the
last decade)
Came across
clojure/scala
around
2010âŚand used
in production
Learning and
using F# since
last year
@work
Occasional
tinkering with
OCaml and
Haskell
3. Problem Statement
⢠We have tons of code written in JAVA
⢠Where will I find developer?
⢠One company one tech stackâŚ
⢠Performance, Monitoring, Support?
⢠Interop, library support.
CAN I STILL WRITE FUNCTIONAL CODE, IMPROVE KPI, MAKE MY LEADERSHIP HAPPY
4. Todayâs JAVA
OOO -> FP
Functional programming is mainstream
since JDK 8 (GA â 2014)
We could use the power of FP ever since
then
Powerful Lambdas/Streams
Collection Enhancements
Function, Supplier, Consumer
5. Growing eco-system
⢠Many promising and production ready libraries
⢠Clean APIs
⢠Reduction of verbosity, testable and concise code
⢠Great dev tools
⢠Rapid learning from other functional programming languages
6. KPI improvements (target areas)
using FP in java
SONAR
DEVELOPER
PRODUCTIVITY
Time to market
GC, PERF
IMPROVEMENT
8. Functional Java : Stream basics
Loop
List<String> countries = new
ArrayList<>();
for (String s : allCountries) {
if (s.startsWith(âI")) {
countries.add(s);
}
}
Stream
List<String> countries
= allCountries.stream()
.filter(a -> a.startsWith(âI"))
.collect(toList())
9. Functional Java : Stream illustrated
Origin EndOp 1 Op 2 Op n
Data Pipeline Start Data Pipeline End
Intermediate
Operations
10. Functional Java : Map, reduce, collect
List<String> list = Stream.of("India", "Iceland",âPeruâ,"Italy")
.filter(s -> s.startsWith("I"))
.map(String::toUpperCase)
.sorted()
.collect(toList())
India Iceland ItalyPeru
India Iceland Italy
INDIA ICELAND ITALY
ICELAND INDIA ITALY
ICELAND INDIA ITALY
1
2
3
4
5
1
2
3
4
5
11. Intermediate Operation : Filter
Ind It UKJP
Ind It
1
2
Stream<String> startsWithI = Stream.of("Ind", "It", "JP", "UK")
.filter(s -> s.startsWith("I"));
1
2
12. Functional Java : Intermediate Operation
Ind It UKJP
Ind It
1
2
Stream<String> startsWithI = Stream.of("Ind", "It", "JP", "UK")
.limit(3);
1
2
JP
13. Functional Java : Intermediate Operation
Ind It UKJP
Ind It
1
2
Stream<String> startsWithI = Stream.of("Ind", "It", "JP", "UK", "UK")
.distinct();
1
2
JP
UK
UK
14. Functional Java : Intermediate Operation
Ind It UKUS
Ind It
1
2
Stream<String> startsWithI = Stream.of("Ind", "It", âUS", "UK")
.sorted();
1
2
UK US
15. Functional Java : Intermediate Operation
Ind It UKUS
Ind It
1
2
Stream<String> startsWithI = Stream.of("Ind", "It", âUS", "UK")
.sorted(Comparator.comparing(String::length));
1
2
UK US
16. Functional Java : Terminal Operation
Ind It UKJP
Ind
It
1
2
Stream<String> startsWithI = Stream.of("Ind", "It", "JP", "UK")
.forEach(System.out.println());
1
2
JP
UK
17. Functional Java : Downstream Collectors
Ind It UKJP
Ind It
1
2
Stream<String> startsWithI = Stream.of("Ind", "It", "JP", "UKâ, "UKâ )
.collect(Collectors.toSet());
1
2
JP UK
UK
18. Functional Java : Custom Downstream collector
return Collector.of(
() -> new ArrayList<T>(), // supplier
(a, e) -> { a.add(e); }, // accumulator
(a, b) -> { a.addAll(b); return a; }, // combiner
a -> { // finisher
a.sort(comp);
DA da = downstream.supplier().get();
for (T e : a)
downstream.accumulator().accept(da, e);
return downstream.finisher().apply(da);
});
Stream<Locale> locales =
Stream.of(Locale.getAvailableLocales());
var result = locales.collect(
groupingBy(Locale::getCountry,
mapping(Locale::getDisplayName,
sorting(String::compareTo,
joining(",")))));
19. Functional Java : Collection enhancemetns
map.forEach((k, v) -> System.out.println(k + v));for (Map.Entry<String,String> entry : map.entrySet())
System.out.println(entry.getKey() + entry.getValue());
for (Map.Entry<String,String> entry : map.entrySet())
entry.setValue(entry.getValue().toLowerCase());
map.replaceAll((k, v) -> v.toLowerCase());
map.computeIfAbsent(str, x -> HashsSet::new).add(i);Set<Integer> set = multimap.get(str);
if (set == null) {
set = new HashSet<>();
multimap.put(str, set);
}
set.add(i);
25. Vavr : basics
⢠New functional data-structures (persistent) with superior
performance
⢠Pure Functions, monads, superior exception management
⢠Less verbosity
⢠Great Functional semantics