Getting value from pair in array

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Getting value from pair in array

Rick Draper-2
Hi All,

I'm having a complete brain fade and I know I have done this before.

If I have an array of pairs (can't use a map as the data is coming from an existing array), what is the syntax to get the value for a particular element??

local(testing) = Array

#testing -> insert('first' = 'red')
#testing -> insert('second' = 'green')
#testing -> insert('third' = 'blue')

// this not correct syntax but shows what I want
'<p>' + #testing -> find('third') -> value + '</p>'

Any slap around the head that can be provided would be appreciated.

Many thanks and best regards,


Rick


#############################################################
This message is sent to you because you are subscribed to
  the mailing list Lasso
[hidden email]
To unsubscribe, E-mail to: <[hidden email]>
Send administrative queries to  <[hidden email]>
Reply | Threaded
Open this post in threaded view
|

Re: Getting value from pair in array

stevepiercy
Hi Rick,

'<p>' + #testing -> find('third') -> size == 1 ? #testing ->
find('third') -> get(1) -> second + '</p>'

--steve


On 1/19/13 at 7:22 AM, [hidden email] (Rick Draper) pronounced:

>Hi All,
>
>I'm having a complete brain fade and I know I have done this before.
>
>If I have an array of pairs (can't use a map as the data is
>coming from an existing array), what is the syntax to get the
>value for a particular element??
>
>local(testing) = Array
>
>#testing -> insert('first' = 'red')
>#testing -> insert('second' = 'green')
>#testing -> insert('third' = 'blue')
>
>// this not correct syntax but shows what I want
>'<p>' + #testing -> find('third') -> value + '</p>'
>
>Any slap around the head that can be provided would be appreciated.
>
>Many thanks and best regards,
>
>
>Rick
>
>
>#############################################################
>This message is sent to you because you are subscribed to
>the mailing list Lasso
>[hidden email]
>To unsubscribe, E-mail to: <[hidden email]>
>Send administrative queries to  <[hidden email]>

-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
-- --
Steve Piercy               Web Site Builder              
Soquel, CA
<[hidden email]>                  <http://www.StevePiercy.com/>

#############################################################
This message is sent to you because you are subscribed to
  the mailing list Lasso
[hidden email]
To unsubscribe, E-mail to: <[hidden email]>
Send administrative queries to  <[hidden email]>
Reply | Threaded
Open this post in threaded view
|

RE: Getting value from pair in array

Rick Draper-2
Thanks Steve,

If I recall correctly, you may have reminded me of that syntax previously - I need it written on the wall for when I need it again in 2 years' time.

Many thanks


-----Original Message-----
From: [hidden email] [mailto:[hidden email]] On Behalf Of Steve Piercy - Web Site Builder
Sent: Saturday, 19 January 2013 7:30 AM
To: [hidden email]
Subject: Re: Getting value from pair in array

Hi Rick,

'<p>' + #testing -> find('third') -> size == 1 ? #testing ->
find('third') -> get(1) -> second + '</p>'

--steve


#############################################################
This message is sent to you because you are subscribed to
  the mailing list Lasso
[hidden email]
To unsubscribe, E-mail to: <[hidden email]>
Send administrative queries to  <[hidden email]>
Reply | Threaded
Open this post in threaded view
|

Re: Getting value from pair in array

Tim Taplin
It may be helpful to remember that when you search an array, you get an array of results even if the result is one element.

so, in your example you got back array(pair('third' = 'blue')) which is where steve's snippet comes into play, grab first element in the array and get its second element, or you could get first element in the array and retrieve its value if you know that  it is a pair


Just a more verbose way of agreeing with Steve's answer that may stick to the wall a little better.

Tim

On Jan 18, 2013, at 2:32 PM, Rick Draper <[hidden email]> wrote:

> Thanks Steve,
>
> If I recall correctly, you may have reminded me of that syntax previously - I need it written on the wall for when I need it again in 2 years' time.
>
> Many thanks
>
>
> -----Original Message-----
> From: [hidden email] [mailto:[hidden email]] On Behalf Of Steve Piercy - Web Site Builder
> Sent: Saturday, 19 January 2013 7:30 AM
> To: [hidden email]
> Subject: Re: Getting value from pair in array
>
> Hi Rick,
>
> '<p>' + #testing -> find('third') -> size == 1 ? #testing ->
> find('third') -> get(1) -> second + '</p>'
>
> --steve
>
>
> #############################################################
> This message is sent to you because you are subscribed to
>  the mailing list Lasso
> [hidden email]
> To unsubscribe, E-mail to: <[hidden email]>
> Send administrative queries to  <[hidden email]>

#############################################################
This message is sent to you because you are subscribed to
  the mailing list Lasso
[hidden email]
To unsubscribe, E-mail to: <[hidden email]>
Send administrative queries to  <[hidden email]>
Reply | Threaded
Open this post in threaded view
|

Re: Getting value from pair in array

Jolle Carlestam-3
Another good point to remember is that while find is forgiving get is not. If you try to find something that's not there lasso will accept that and just return an empty array. But if you attempt to get an element that's out of range lasso will throw an error. Thus Steves code first checking that the find actually finds something before using the get.

HDB
Jolle

Sent from a thin, flat, touchy device from an undetermined place in space.

18 jan 2013 kl. 22:53 skrev "Tim Taplin" <[hidden email]>:

> It may be helpful to remember that when you search an array, you get an array of results even if the result is one element.
>
> so, in your example you got back array(pair('third' = 'blue')) which is where steve's snippet comes into play, grab first element in the array and get its second element, or you could get first element in the array and retrieve its value if you know that  it is a pair
>
>
> Just a more verbose way of agreeing with Steve's answer that may stick to the wall a little better.
>
> Tim
>
> On Jan 18, 2013, at 2:32 PM, Rick Draper <[hidden email]> wrote:
>
>> Thanks Steve,
>>
>> If I recall correctly, you may have reminded me of that syntax previously - I need it written on the wall for when I need it again in 2 years' time.
>>
>> Many thanks
>>
>>
>> -----Original Message-----
>> From: [hidden email] [mailto:[hidden email]] On Behalf Of Steve Piercy - Web Site Builder
>> Sent: Saturday, 19 January 2013 7:30 AM
>> To: [hidden email]
>> Subject: Re: Getting value from pair in array
>>
>> Hi Rick,
>>
>> '<p>' + #testing -> find('third') -> size == 1 ? #testing ->
>> find('third') -> get(1) -> second + '</p>'
>>
>> --steve
>>
>>
>> #############################################################
>> This message is sent to you because you are subscribed to
>> the mailing list Lasso
>> [hidden email]
>> To unsubscribe, E-mail to: <[hidden email]>
>> Send administrative queries to  <[hidden email]>
>
> #############################################################
> This message is sent to you because you are subscribed to
>  the mailing list Lasso
> [hidden email]
> To unsubscribe, E-mail to: <[hidden email]>
> Send administrative queries to  <[hidden email]>
>
>
#############################################################
This message is sent to you because you are subscribed to
  the mailing list Lasso
[hidden email]
To unsubscribe, E-mail to: <[hidden email]>
Send administrative queries to  <[hidden email]>