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)
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)

--

--

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