- About Scala
- Documentation
- Code Examples
- Software
- Scala Developers
Best way to prepone an option to a List
Wed, 2012-01-25, 16:32
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
Wed, 2012-01-25, 17:01
#2
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
Wed, 2012-01-25, 17:11
#3
Re: Best way to prepone an option to a List
Well... what is the question between ++ and ::: ?
Best Regards
2012/1/25 Dennis Haupt <h-star@gmx.de>
Best Regards
2012/1/25 Dennis Haupt <h-star@gmx.de>
easiest way : a.toList ++ list
-------- Original-Nachricht --------
> Datum: Wed, 25 Jan 2012 16:32:03 +0100
> Von: Edmondo Porcu <edmondo.porcu@gmail.com>
> An: scala-user <scala-user@googlegroups.com>
> 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
Wed, 2012-01-25, 17:21
#4
Re: Best way to prepone an option to a List
a ++: list might be even easier.
On 25 January 2012 16:44, Dennis Haupt <h-star@gmx.de> wrote:
On 25 January 2012 16:44, Dennis Haupt <h-star@gmx.de> wrote:
easiest way : a.toList ++ list
Wed, 2012-01-25, 20:31
#5
Re: Best way to prepone an option to a List
++ delegates to ::: in case of a list
or something like this.
the :: and ::: methods are list only
Am 25.01.2012 16:53, schrieb Edmondo Porcu:
or something like this.
the :: and ::: methods are list only
Am 25.01.2012 16:53, schrieb Edmondo Porcu:
6QXs6jg [at] mail [dot] gmail [dot] com" type="cite">Well... what is the question between ++ and ::: ?
Best Regards
2012/1/25 Dennis Haupt <h-star [at] gmx [dot] de" target="_blank" rel="nofollow">h-star@gmx.de>
easiest way : a.toList ++ list
-------- Original-Nachricht --------
> Datum: Wed, 25 Jan 2012 16:32:03 +0100
> Von: Edmondo Porcu <edmondo [dot] porcu [at] gmail [dot] com" target="_blank" rel="nofollow">edmondo.porcu@gmail.com>
> An: scala-user <scala-user [at] googlegroups [dot] com" target="_blank" rel="nofollow">scala-user@googlegroups.com>
> 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
Option(3).toList ::: list
--Rex
On Wed, Jan 25, 2012 at 10:32 AM, Edmondo Porcu <edmondo.porcu@gmail.com> wrote: