- About Scala
- Documentation
- Code Examples
- Software
- Scala Developers
Best way to prepone an option to a List
Dear all,I have the following case:
val a :Option[Int] = Some(3);
val list = List(1,2,3);
I would like to create a new list prepending a to list.
Of course, if a is None no value has to be prepended.
What is the best way to do this?
Best RegardsEdmondo
val a :Option[Int] = Some(3);
val list = List(1,2,3);
I would like to create a new list prepending a to list.
Of course, if a is None no value has to be prepended.
What is the best way to do this?
Best RegardsEdmondo










Re: Best way to prepone an option to a List
easiest way : a.toList ++ list
-------- Original-Nachricht --------
> Datum: Wed, 25 Jan 2012 16:32:03 +0100
> Von: Edmondo Porcu
> An: scala-user
> Betreff: [scala-user] Best way to prepone an option to a List
> Dear all,
> I have the following case:
>
> val a :Option[Int] = Some(3);
>
> val list = List(1,2,3);
>
> I would like to create a new list prepending a to list.
>
> Of course, if a is None no value has to be prepended.
>
> What is the best way to do this?
>
> Best Regards
> Edmondo
Re: Best way to prepone an option to a List
On 25 January 2012 16:44, Dennis Haupt <h-star [at] gmx [dot] de> wrote:
Re: Best way to prepone an option to a List
Best Regards
2012/1/25 Dennis Haupt <h-star [at] gmx [dot] de>
Re: Best way to prepone an option to a List
or something like this.
the :: and ::: methods are list only
Am 25.01.2012 16:53, schrieb Edmondo Porcu:
Re: Best way to prepone an option to a List
Option(3).toList ::: list
--Rex
On Wed, Jan 25, 2012 at 10:32 AM, Edmondo Porcu <edmondo [dot] porcu [at] gmail [dot] com> wrote: