val surnames: Seq[String] = ...
val page1 = surnames filter {_.head.toLower == 'a'} take 50
val page1uc = page1 map {_.toUpperCase}It doesn't matter if surnames is empty, or no entry starts with the letter 'a', or if less than 50 entries map. It all just works and flows effortlessly with no explicit checking for nulls or emptiness. page1uc will contain a sequence of between 0 and 50 uppercased names starting with 'A', it's fully typesafe and statically guaranteed. On 5 June 2012 22:14, Fabrizio Giudici <[email protected]>wrote: > On Tue, 05 Jun 2012 22:28:41 +0200, Cédric Beust ♔ <[email protected]> > wrote: > > > In an ideal world, the default case never crashes (empty collections) but >> the language gives me a way to crash immediately if I receive >> null/None/Nothing (without me having to explicitly test for it). >> > > In my own stuff, I have finder methods that, when a result is expected, > throw a NotFoundException. It all depends on the case. OTOH there's a point > in returning an empty collection rather than null: that people, "in doubt", > would anyway write > > List<> l = ... > > if ((l != null) && !l.isEmpty()) > > which I hate. Being sure that l is not null, you can at least omit the (l > != null). > > > > -- You received this message because you are subscribed to the Google Groups "Java Posse" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/javaposse?hl=en.
