Converting a tuple of options to an option of tuple with Scalaz or Shapeless

后端 未结 5 1430
误落风尘
误落风尘 2020-12-15 06:45

Having

(Some(1), Some(2))

I expect to get

Some((1, 2))

and having

(Some(1), None)
         


        
5条回答
  •  无人及你
    2020-12-15 07:16

    I realize you're asking about Scalaz, but it's worth pointing out that the standard method is not unbearably wordy:

    val x = (Some(1), Some(2))
    
    for (a <- x._1; b <-x._2) yield (a,b)
    

    In the general case (e.g. arbitrary-arity tuples), Shapeless is best at this sort of thing.

提交回复
热议问题