RE: [Flashcoders] Vector.map()

2011-08-19 Thread Mendelsohn, Michael
It sure seems like the documentation is off from what it actually does.  Maybe 
in the mapper function, you can push each iteration out to a new array instead. 
 :-/\

Good luck!
- Michael M.

-Original Message-
From: Kenneth Kawamoto [mailto:kennethkawam...@gmail.com] 
Sent: Friday, August 19, 2011 9:14 AM
To: Mendelsohn, Michael
Cc: kennethkawam...@gmail.com; Flash Coders List
Subject: Re: [Flashcoders] Vector.map()

private function arrayMapper(item:uint, index:uint, array:Array):uint {
return item + 30;
}
trace([1, 2, 3, 4, 5].map(arrayMapper));
// traces 31,32,33,34,35

Array.map() does what it says it does.

private function vectorMapper(item:uint, index:uint, 
vector:Vector.):uint {
return item + 30;
}
trace(new [1, 2, 3, 4, 5].map(vectorMapper));
// traces undefined

Vector.map() does, well, f-all. I can use forEach() to get what I want 
but this doesn't look right.

Thanks for testing MM!

Kenneth Kawamoto
http://www.materiaprima.co.uk/

On 19/08/2011 13:36, Mendelsohn, Michael wrote:
> You're right Kenneth.
>
> var g:Vector.  = Vector.([1,2,3,4,5]);
> var hh:Vector.  = g.slice();
> var h:Vector.  = g.map(mapper);
> var a = 5;
> function mapper(item:uint,ind:uint,g:Vector.):Vector.{
>   trace(g[ind]+30);
>   return g;
> }
>
> In this case, hh returns the vector, and h still returns null.
>
> - MM
>
> -Original Message-
> From: Kenneth Kawamoto [mailto:kennethkawam...@gmail.com]
> Sent: Thursday, August 18, 2011 5:15 PM
> To: Flash Coders List
> Cc: Mendelsohn, Michael
> Subject: Re: [Flashcoders] Vector.map()
>
> What do you get for h?
>
> Kenneth Kawamoto
> http://www.materiaprima.co.uk/
>
> On 18/08/2011 21:08, Mendelsohn, Michael wrote:
>> Hi Kenneth...
>>
>> This is working for me:
>>
>> var g:Vector.   = Vector.([1,2,3,4,5]);
>> var h:Vector.   = g.map(mapper);
>> function mapper(item:uint,ind:uint,g:Vector.):void{
>>  trace(g[ind]+30);
>> }
>>
>> Hope that helps,
>> - Michael M.
>>
>>
>>
>> -Original Message-
>> From: flashcoders-boun...@chattyfig.figleaf.com 
>> [mailto:flashcoders-boun...@chattyfig.figleaf.com] On Behalf Of Kenneth 
>> Kawamoto
>> Sent: Thursday, August 18, 2011 9:27 AM
>> To: Flash Coders List
>> Subject: [Flashcoders] Vector.map()
>>
>> Dear coders,
>>
>> Vector.map() is supposed to return a new Vector but it appears to return
>> nothing (undefined). Is this working for you?

___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


RE: [Flashcoders] Vector.map()

2011-08-19 Thread Dennis Ernst
function mapper needs to return an element of the new vector.  In this 
case, the vector is a vector of  uint, so the mapper function needs to 
return a uint, not a Vector.  This makes sense because mapper is called 
for every item in g.  Say you wanted to populate h with the squares of 
each element in g, you would return item * item.



Ernie

On 8/19/2011 9:00 AM, flashcoders-requ...@chattyfig.figleaf.com wrote:

Message: 3
Date: Fri, 19 Aug 2011 08:36:30 -0400
From: "Mendelsohn, Michael"
Subject: RE: [Flashcoders] Vector.map()
To: "kennethkawam...@gmail.com", Flash
Coders List 
Message-ID:



Content-Type: text/plain; charset="us-ascii"

You're right Kenneth.

var g:Vector.  = Vector.([1,2,3,4,5]);
var hh:Vector.  = g.slice();
var h:Vector.  = g.map(mapper);
var a = 5;
function mapper(item:uint,ind:uint,g:Vector.):Vector.{
trace(g[ind]+30);
return g;
}

In this case, hh returns the vector, and h still returns null.

- MM

-Original Message-
From: Kenneth Kawamoto [mailto:kennethkawam...@gmail.com]
Sent: Thursday, August 18, 2011 5:15 PM
To: Flash Coders List
Cc: Mendelsohn, Michael
Subject: Re: [Flashcoders] Vector.map()

What do you get for h?

Kenneth Kawamoto
http://www.materiaprima.co.uk/

On 18/08/2011 21:08, Mendelsohn, Michael wrote:

Hi Kenneth...

This is working for me:

var g:Vector.   = Vector.([1,2,3,4,5]);
var h:Vector.   = g.map(mapper);
function mapper(item:uint,ind:uint,g:Vector.):void{
trace(g[ind]+30);
}

Hope that helps,
- Michael M.



-Original Message-
From: flashcoders-boun...@chattyfig.figleaf.com 
[mailto:flashcoders-boun...@chattyfig.figleaf.com] On Behalf Of Kenneth Kawamoto
Sent: Thursday, August 18, 2011 9:27 AM
To: Flash Coders List
Subject: [Flashcoders] Vector.map()

Dear coders,

Vector.map() is supposed to return a new Vector but it appears to return
nothing (undefined). Is this working for you?




___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


Re: [Flashcoders] Vector.map()

2011-08-19 Thread Kenneth Kawamoto

private function arrayMapper(item:uint, index:uint, array:Array):uint {
   return item + 30;
}
trace([1, 2, 3, 4, 5].map(arrayMapper));
// traces 31,32,33,34,35

Array.map() does what it says it does.

private function vectorMapper(item:uint, index:uint, 
vector:Vector.):uint {

   return item + 30;
}
trace(new [1, 2, 3, 4, 5].map(vectorMapper));
// traces undefined

Vector.map() does, well, f-all. I can use forEach() to get what I want 
but this doesn't look right.


Thanks for testing MM!

Kenneth Kawamoto
http://www.materiaprima.co.uk/

On 19/08/2011 13:36, Mendelsohn, Michael wrote:

You're right Kenneth.

var g:Vector.  = Vector.([1,2,3,4,5]);
var hh:Vector.  = g.slice();
var h:Vector.  = g.map(mapper);
var a = 5;
function mapper(item:uint,ind:uint,g:Vector.):Vector.{
trace(g[ind]+30);
return g;
}

In this case, hh returns the vector, and h still returns null.

- MM

-Original Message-
From: Kenneth Kawamoto [mailto:kennethkawam...@gmail.com]
Sent: Thursday, August 18, 2011 5:15 PM
To: Flash Coders List
Cc: Mendelsohn, Michael
Subject: Re: [Flashcoders] Vector.map()

What do you get for h?

Kenneth Kawamoto
http://www.materiaprima.co.uk/

On 18/08/2011 21:08, Mendelsohn, Michael wrote:

Hi Kenneth...

This is working for me:

var g:Vector.   = Vector.([1,2,3,4,5]);
var h:Vector.   = g.map(mapper);
function mapper(item:uint,ind:uint,g:Vector.):void{
trace(g[ind]+30);
}

Hope that helps,
- Michael M.



-Original Message-
From: flashcoders-boun...@chattyfig.figleaf.com 
[mailto:flashcoders-boun...@chattyfig.figleaf.com] On Behalf Of Kenneth Kawamoto
Sent: Thursday, August 18, 2011 9:27 AM
To: Flash Coders List
Subject: [Flashcoders] Vector.map()

Dear coders,

Vector.map() is supposed to return a new Vector but it appears to return
nothing (undefined). Is this working for you?

___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


RE: [Flashcoders] Vector.map()

2011-08-19 Thread Mendelsohn, Michael
You're right Kenneth.

var g:Vector. = Vector.([1,2,3,4,5]);
var hh:Vector. = g.slice();
var h:Vector. = g.map(mapper);
var a = 5;
function mapper(item:uint,ind:uint,g:Vector.):Vector.{
trace(g[ind]+30);
return g;
}

In this case, hh returns the vector, and h still returns null.

- MM

-Original Message-
From: Kenneth Kawamoto [mailto:kennethkawam...@gmail.com] 
Sent: Thursday, August 18, 2011 5:15 PM
To: Flash Coders List
Cc: Mendelsohn, Michael
Subject: Re: [Flashcoders] Vector.map()

What do you get for h?

Kenneth Kawamoto
http://www.materiaprima.co.uk/

On 18/08/2011 21:08, Mendelsohn, Michael wrote:
> Hi Kenneth...
>
> This is working for me:
>
> var g:Vector.  = Vector.([1,2,3,4,5]);
> var h:Vector.  = g.map(mapper);
> function mapper(item:uint,ind:uint,g:Vector.):void{
>   trace(g[ind]+30);
> }
>
> Hope that helps,
> - Michael M.
>
>
>
> -Original Message-
> From: flashcoders-boun...@chattyfig.figleaf.com 
> [mailto:flashcoders-boun...@chattyfig.figleaf.com] On Behalf Of Kenneth 
> Kawamoto
> Sent: Thursday, August 18, 2011 9:27 AM
> To: Flash Coders List
> Subject: [Flashcoders] Vector.map()
>
> Dear coders,
>
> Vector.map() is supposed to return a new Vector but it appears to return
> nothing (undefined). Is this working for you?

___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


Re: [Flashcoders] Vector.map()

2011-08-18 Thread Kenneth Kawamoto

What do you get for h?

Kenneth Kawamoto
http://www.materiaprima.co.uk/

On 18/08/2011 21:08, Mendelsohn, Michael wrote:

Hi Kenneth...

This is working for me:

var g:Vector.  = Vector.([1,2,3,4,5]);
var h:Vector.  = g.map(mapper);
function mapper(item:uint,ind:uint,g:Vector.):void{
trace(g[ind]+30);
}

Hope that helps,
- Michael M.



-Original Message-
From: flashcoders-boun...@chattyfig.figleaf.com 
[mailto:flashcoders-boun...@chattyfig.figleaf.com] On Behalf Of Kenneth Kawamoto
Sent: Thursday, August 18, 2011 9:27 AM
To: Flash Coders List
Subject: [Flashcoders] Vector.map()

Dear coders,

Vector.map() is supposed to return a new Vector but it appears to return
nothing (undefined). Is this working for you?

___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


RE: [Flashcoders] Vector.map()

2011-08-18 Thread Mendelsohn, Michael
Hi Kenneth...

This is working for me:

var g:Vector. = Vector.([1,2,3,4,5]);
var h:Vector. = g.map(mapper);
function mapper(item:uint,ind:uint,g:Vector.):void{
trace(g[ind]+30);
}

Hope that helps,
- Michael M.



-Original Message-
From: flashcoders-boun...@chattyfig.figleaf.com 
[mailto:flashcoders-boun...@chattyfig.figleaf.com] On Behalf Of Kenneth Kawamoto
Sent: Thursday, August 18, 2011 9:27 AM
To: Flash Coders List
Subject: [Flashcoders] Vector.map()

Dear coders,

Vector.map() is supposed to return a new Vector but it appears to return 
nothing (undefined). Is this working for you?


___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders