scala - Option.zip returns List, not Option -



scala - Option.zip returns List, not Option -

standard library documentation describes zip partial signature def zip[b](that: geniterable[b]): option[(a, b)] some(1) zip some(2) returns list((1,2)) not some((1,2)). case of buggy implementation or buggy documentation?

buggy documentation.

zip defined on iterable, , it's applicable option due implicit conversion option2iterable (this explicitly stated in documentation if closely).

for reason option first converted iterable , zip operation supported.

this done code reuse, misses case in iterable methods create sense straight on option without need of implicit conversion.

here's relevant give-and-take in mailing list: https://groups.google.com/forum/#!topic/scala-language/mfu5ppt_jyw

if need zip 2 options, can utilize workaround:

(opt1 zip opt2).headoption

also, travis noted in comments, alternatively leverage scalaz zip type class, although have utilize fzip instead.

opt1 fzip opt2

scala

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -