@avibryant opt.getOrElse(Nil).map(_ * 2)
-
-
-
.
@d6 yeah, that's nicer. Thanks. - 1 more reply
New conversation -
-
-
@avibryant Option[List[Int]] is smelly isn't it? None should just be an empty List[Int], no? -
@snoble I agree. That's what scrooge generates for `optional list<string>` though. -
@avibryant then opt.getOrElse(…).map(…) seems more clear to me
End of conversation
New conversation -
-
-
@avibryant Flatmaps and maps. Isn’t that a for comprehension… -
@arsatiki yeah, it's not much nicer as a for, though. The main annoying thing is the toList. -
@avibryant@arsatiki shortest I've got is opt.map(_.map(_ * 2)).toList.flatten. *shrug* -
@alexcruise@avibryant@arsatiki I think I beat you on this one :) -
@d6 yeah, gets at the essence of the example better. /cc@avibryant@arsatiki
End of conversation
New conversation -
-
-
@avibryant “@sorenmacbeth: Use Clojure”Thanks. Twitter will use this to make your timeline better. UndoUndo
-
-
-
@avibryant def foo(opt:Option[List[Int]]) = for (i <- opt.getOrElse(Nil)) yield(i*2) is a little more concise, but not "pretty". -
@deanwampler@avibryant Another version is opt.map(_.map(_ * 2)).getOrElse(Nil) It's kinda hard to determine which is the prettiest
End of conversation
New conversation -
-
-
@avibryant opt.fold(nil[Int])(_.map(_ * 2))Thanks. Twitter will use this to make your timeline better. UndoUndo
-
-
-
@avibryant More verbose than@d6, but what about def foo(opt: Option[List[Int]]) = opt.toList.flatten.map { n => n * 2 }Thanks. Twitter will use this to make your timeline better. UndoUndo
-
Loading seems to be taking a while.
Twitter may be over capacity or experiencing a momentary hiccup. Try again or visit Twitter Status for more information.