Re: What's the easiest way to flatten nested Options
The easiest and most generic way requires third-party library support
(see Scalaz). What you are describing is called a "Traversable" (see
scalaz.Traverse, specifically the Tuple2[T, _] instance).
This paper describes it best http://www.comlab.ox.ac.uk/jeremy.gibbons/publications/iterator.pdf
It's a good exercise to play with these abstractions, so I'll leave it here.
John Ky wrote:
> Hi,
>
> If I have a value that looks something like this: (0, Some((1, Some(2))))
>
> And I want to flatten it into this: (Some(0), Some(1), Some(2))
>
> What is the easiest and most generic way of doing this?
>
> Cheers,
>
> -John
>
The easiest and most generic way requires third-party library support
(see Scalaz). What you are describing is called a "Traversable" (see
scalaz.Traverse, specifically the Tuple2[T, _] instance).
This paper describes it best
http://www.comlab.ox.ac.uk/jeremy.gibbons/publications/iterator.pdf
It's a good exercise to play with these abstractions, so I'll leave it here.
John Ky wrote:
> Hi,
>
> If I have a value that looks something like this: (0, Some((1, Some(2))))
>
> And I want to flatten it into this: (Some(0), Some(1), Some(2))
>
> What is the easiest and most generic way of doing this?
>
> Cheers,
>
> -John
>