- About Scala
- Documentation
- Code Examples
- Software
- Scala Developers
Use case for map method on Map class
Thu, 2010-08-12, 19:39
The use case for the map method on the Map class is this:
defmap [B] (f: ((A, B)) ⇒ B) : Map[B]
That seems confusing, at the least. I didn't see any obvious way of fixing it either, since Map does not override this method. Is this a known issue? Am I worrying too much about it?
defmap [B] (f: ((A, B)) ⇒ B) : Map[B]
That seems confusing, at the least. I didn't see any obvious way of fixing it either, since Map does not override this method. Is this a known issue? Am I worrying too much about it?
Sat, 2010-08-14, 00:17
#2
Re: Re: Use case for map method on Map class
On Fri, Aug 13, 2010 at 7:37 PM, Tobias Neef <tobnee@gmail.com> wrote:
Daniel Sobral <dcsobral <at> gmail.com> writes:
>
>
> The use case for the map method on the Map class is this:
>
>
>
>
> defmap [B] (f: ((A, B)) ⇒ B) : Map[B]
>
>
>
> That seems confusing, at the least. I didn't see any obvious way of fixing it
either, since Map does not override this method. Is this a known issue? Am I
worrying too much about it?
>
>
Hi Daniel,
I am not sure what you want to do. This is the signature of the map method not a
use case. And what is wrong with it?
Here is a list of some good examples:
http://programming-scala.labs.oreilly.com/ch08.html
Well, try this: Map(1 -> 2).map { case (a, b) => b * 2 }
I daresay you'll not get a Map[Int] as result, contrary to what is indicated by the type signature in the scaladoc..
--
Daniel C. Sobral
I travel to the future all the time.
Sat, 2010-08-14, 00:27
#3
Re: Re: Use case for map method on Map class
The obvious question in this expression: def map [B] (f: ((A, B)) ⇒ B) : Map[B]is "What is B?"
Even then, it's a trick question until you specify *which* B you're asking about. The second B is not the same as the 1st, 3rd and 4th
Perhaps it would be clearer if I used K and V for key and value types, and R for the result: def map [R] (f: ((K, V)) ⇒ R) : Map[R]
Which makes sense if you understand that Map extends Iterable[A,B], and inherits the map operation from there.But definitely fails to clarify that you're mapping a Pair to a Pair, and that the resulting Map can have both key and value types different from the original
So... the type param [B] in that method shadows the same-named type param from the containing Map class and it appears to be returning a Map with only one type parameter provided, whereas Map quite clearly take two such parameters
Something like this would be more appropriate.
def map [C,D] (f: ((A, B)) ⇒ (C,D)) : Map[C,D]
Yes, I fully appreciate that the map operation can also be used to return another non-map Iterable type here.But we are, very specifically, discussing the simplified [use case] in the documentation
On 13 August 2010 23:37, Tobias Neef <tobnee@gmail.com> wrote:
--
Kevin Wright
mail/google talk: kev.lee.wright@gmail.com
wave: kev.lee.wright@googlewave.com
skype: kev.lee.wright
twitter: @thecoda
Even then, it's a trick question until you specify *which* B you're asking about. The second B is not the same as the 1st, 3rd and 4th
Perhaps it would be clearer if I used K and V for key and value types, and R for the result: def map [R] (f: ((K, V)) ⇒ R) : Map[R]
Which makes sense if you understand that Map extends Iterable[A,B], and inherits the map operation from there.But definitely fails to clarify that you're mapping a Pair to a Pair, and that the resulting Map can have both key and value types different from the original
So... the type param [B] in that method shadows the same-named type param from the containing Map class and it appears to be returning a Map with only one type parameter provided, whereas Map quite clearly take two such parameters
Something like this would be more appropriate.
def map [C,D] (f: ((A, B)) ⇒ (C,D)) : Map[C,D]
Yes, I fully appreciate that the map operation can also be used to return another non-map Iterable type here.But we are, very specifically, discussing the simplified [use case] in the documentation
On 13 August 2010 23:37, Tobias Neef <tobnee@gmail.com> wrote:
Daniel Sobral <dcsobral <at> gmail.com> writes:
>
>
> The use case for the map method on the Map class is this:
>
>
>
>
> defmap [B] (f: ((A, B)) ⇒ B) : Map[B]
>
>
>
> That seems confusing, at the least. I didn't see any obvious way of fixing it
either, since Map does not override this method. Is this a known issue? Am I
worrying too much about it?
>
>
Hi Daniel,
I am not sure what you want to do. This is the signature of the map method not a
use case. And what is wrong with it?
Here is a list of some good examples:
http://programming-scala.labs.oreilly.com/ch08.html
--
Kevin Wright
mail/google talk: kev.lee.wright@gmail.com
wave: kev.lee.wright@googlewave.com
skype: kev.lee.wright
twitter: @thecoda
Sat, 2010-08-14, 00:37
#4
Re: Re: Use case for map method on Map class
Except that type signature would be a lie -- but I assume that to be fine given the context of "use case". The proper type signature to pass is something like this:
Map('a' -> "abc").map[(Int,Int),Map[Int,Int]]{case (a, b) => (a.toInt, b.length)}
On Fri, Aug 13, 2010 at 8:16 PM, Kevin Wright <kev.lee.wright@gmail.com> wrote:
--
Daniel C. Sobral
I travel to the future all the time.
Map('a' -> "abc").map[(Int,Int),Map[Int,Int]]{case (a, b) => (a.toInt, b.length)}
On Fri, Aug 13, 2010 at 8:16 PM, Kevin Wright <kev.lee.wright@gmail.com> wrote:
The obvious question in this expression: def map [B] (f: ((A, B)) ⇒ B) : Map[B]is "What is B?"
Even then, it's a trick question until you specify *which* B you're asking about. The second B is not the same as the 1st, 3rd and 4th
Perhaps it would be clearer if I used K and V for key and value types, and R for the result: def map [R] (f: ((K, V)) ⇒ R) : Map[R]
Which makes sense if you understand that Map extends Iterable[A,B], and inherits the map operation from there.But definitely fails to clarify that you're mapping a Pair to a Pair, and that the resulting Map can have both key and value types different from the original
So... the type param [B] in that method shadows the same-named type param from the containing Map class and it appears to be returning a Map with only one type parameter provided, whereas Map quite clearly take two such parameters
Something like this would be more appropriate.
def map [C,D] (f: ((A, B)) ⇒ (C,D)) : Map[C,D]
Yes, I fully appreciate that the map operation can also be used to return another non-map Iterable type here.But we are, very specifically, discussing the simplified [use case] in the documentation
On 13 August 2010 23:37, Tobias Neef <tobnee@gmail.com> wrote:Daniel Sobral <dcsobral <at> gmail.com> writes:
>
>
> The use case for the map method on the Map class is this:
>
>
>
>
> defmap [B] (f: ((A, B)) ⇒ B) : Map[B]
>
>
>
> That seems confusing, at the least. I didn't see any obvious way of fixing it
either, since Map does not override this method. Is this a known issue? Am I
worrying too much about it?
>
>
Hi Daniel,
I am not sure what you want to do. This is the signature of the map method not a
use case. And what is wrong with it?
Here is a list of some good examples:
http://programming-scala.labs.oreilly.com/ch08.html
--
Kevin Wright
mail/google talk: kev.lee.wright@gmail.com
wave: kev.lee.wright@googlewave.com
skype: kev.lee.wright
twitter: @thecoda
--
Daniel C. Sobral
I travel to the future all the time.
Daniel Sobral gmail.com> writes:
>
>
> The use case for the map method on the Map class is this:
>
>
>
>
> defmap [B] (f: ((A, B)) ⇒ B) : Map[B]
>
>
>
> That seems confusing, at the least. I didn't see any obvious way of fixing it
either, since Map does not override this method. Is this a known issue? Am I
worrying too much about it?
>
>
Hi Daniel,
I am not sure what you want to do. This is the signature of the map method not a
use case. And what is wrong with it?
Here is a list of some good examples:
http://programming-scala.labs.oreilly.com/ch08.html