Hacker News new | past | comments | ask | show | jobs | submit login

It always bothered me that Java8 and Guava optionals don't just implement Iterable. There must be a good reason for this, and I'm guessing they're worried about confusion when you have an `Iterable<List<T>>` but still, it'd be really nice to be able to just write

   for (T result : potentialResult ) {
      //...   
   }
I agree with you, that just seems so much more idiomatic than

    if (potentialResult.isPresent()) {
       T result = potentialResult.get();
    }
But maybe it comes from my mental model of Optional being a 0- or 1-length collection. It's at least definitely treated as a functor in that for pure functional operations, you have .map (or .transform for Guava).



The Guava authors believed Iterable would be confusing without calling .asSet() first.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: