Java is silly. Stays there coz Python is more silly

public class Silliness {  public static void main(String[] args) {
Map<String, String> mapp = new HashMap<>();
mapp.put("afsal", null);
Optional.ofNullable("afsal")
.map(mapp::get).map(String::toUpperCase)); // works but wrong
Optional.ofNullable("afsal")
.map(v -> mapp.get(v).toUpperCase())); // fails, but right
}
functor.map(f).map(g) === functor.map(g compose f)

How about in Scala (and other comparatively better languages) ?

val map: Map[String, string] = Map() // Just nothingSome("afsal").map(v => map.get(v).toUpperCase) 
// Compile failure, coz map.get(v) returns an Option, and it is!
// This leads a developer to do the following
Some("afsal").flatmap(v => map.get(v)).map(_.toUpperCase)

Why Python now from no-where?

--

--

--

A software engineer and a functional programming enthusiast at Simple-machines, Sydney, and a hardcore hiking fan. https://twitter.com/afsalt2

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

RCE in PHP or how to bypass disable_functions in PHP installations

Forwardslash

The Trick with Number System

I am gonna start a 100DaysofCode Challenge!

Basic VPC CIDR

Working at InfluxData: My Experience as a Remote Intern

What Should You Do When You Are Stuck on a Programming Problem?

People pushing a van on a dirt road

Development Update 06.18–07.02

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Afsal Thaj

Afsal Thaj

A software engineer and a functional programming enthusiast at Simple-machines, Sydney, and a hardcore hiking fan. https://twitter.com/afsalt2

More from Medium

How to Install and Set Up an Apache Spark Cluster on Hadoop — Ubuntu 20.04 (Using VirtualBox)

Scala Anonymous Functions, Map and Filter Functions Explained: Significant Topics in Functional…

Apache Spark Typed/Untyped API and UDF Processing Performance

For loop example with explanation using Java