index of element matching block

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

index of element matching block

NorbertHartl
I just discovered that there is no method like

indexOf: aBlock

where the index of the element matching the block is returned. What would be the usual way to achieve this functionality?

Norbert


Reply | Threaded
Open this post in threaded view
|

Re: index of element matching block

Sven Van Caekenberghe-2
#( 11 7 4 21 ) detectIndex: #even

;-)

On 12 Feb 2014, at 12:37, Norbert Hartl <[hidden email]> wrote:

> I just discovered that there is no method like
>
> indexOf: aBlock
>
> where the index of the element matching the block is returned. What would be the usual way to achieve this functionality?
>
> Norbert
>
>


Reply | Threaded
Open this post in threaded view
|

Re: index of element matching block

NorbertHartl

Am 12.02.2014 um 11:44 schrieb Sven Van Caekenberghe <[hidden email]>:

> #( 11 7 4 21 ) detectIndex: #even
>
I knew it makes sense to ask. Only slightly embarrasing :)

Norbert

> ;-)
>
> On 12 Feb 2014, at 12:37, Norbert Hartl <[hidden email]> wrote:
>
>> I just discovered that there is no method like
>>
>> indexOf: aBlock
>>
>> where the index of the element matching the block is returned. What would be the usual way to achieve this functionality?
>>
>> Norbert
>>
>>
>
>


Reply | Threaded
Open this post in threaded view
|

Re: index of element matching block

Sven Van Caekenberghe-2

On 12 Feb 2014, at 13:02, Norbert Hartl <[hidden email]> wrote:

>
> Am 12.02.2014 um 11:44 schrieb Sven Van Caekenberghe <[hidden email]>:
>
>> #( 11 7 4 21 ) detectIndex: #even
>>
> I knew it makes sense to ask. Only slightly embarrasing :)

These little challenges are always quite fun.

Sven

> Norbert
>
>> ;-)
>>
>> On 12 Feb 2014, at 12:37, Norbert Hartl <[hidden email]> wrote:
>>
>>> I just discovered that there is no method like
>>>
>>> indexOf: aBlock
>>>
>>> where the index of the element matching the block is returned. What would be the usual way to achieve this functionality?
>>>
>>> Norbert
>>>
>>>
>>
>>
>
>


Reply | Threaded
Open this post in threaded view
|

Re: index of element matching block

NorbertHartl

Am 12.02.2014 um 12:25 schrieb Sven Van Caekenberghe <[hidden email]>:

>
> On 12 Feb 2014, at 13:02, Norbert Hartl <[hidden email]> wrote:
>
>>
>> Am 12.02.2014 um 11:44 schrieb Sven Van Caekenberghe <[hidden email]>:
>>
>>> #( 11 7 4 21 ) detectIndex: #even
>>>
>> I knew it makes sense to ask. Only slightly embarrasing :)
>
> These little challenges are always quite fun.
>
Yep, because the closest I could create was using withIndexDo: and looking at #detectIndex:ifNone: confirms that.

thanks,

Norbert
 

> Sven
>
>> Norbert
>>
>>> ;-)
>>>
>>> On 12 Feb 2014, at 12:37, Norbert Hartl <[hidden email]> wrote:
>>>
>>>> I just discovered that there is no method like
>>>>
>>>> indexOf: aBlock
>>>>
>>>> where the index of the element matching the block is returned. What would be the usual way to achieve this functionality?
>>>>
>>>> Norbert
>>>>
>>>>
>>>
>>>
>>
>>
>
>


Reply | Threaded
Open this post in threaded view
|

Re: index of element matching block

Ben Coman
In reply to this post by NorbertHartl
Norbert Hartl wrote:
Am 12.02.2014 um 11:44 schrieb Sven Van Caekenberghe [hidden email]:

  
#( 11 7 4 21 ) detectIndex: #even

    
I knew it makes sense to ask. Only slightly embarrasing :)
  
Thanks for asking. I learnt something new.
cheers -ben
Norbert

  
;-)

On 12 Feb 2014, at 12:37, Norbert Hartl [hidden email] wrote:

    
I just discovered that there is no method like

indexOf: aBlock

where the index of the element matching the block is returned. What would be the usual way to achieve this functionality?

Norbert


      
    



  

Reply | Threaded
Open this post in threaded view
|

Re: index of element matching block

NorbertHartl
We should do that more often. Especially here on the users list. IMHO it has three advantages:

- asking here may show new ways of doing things. And we know in smalltalk it is most of the time the most obvious choice we do not find 
- I assume there are quite some readers in this list which have fun answering and trying things out if they do not know it. Sven is a good example for that. I’m just an example :)
- Everyone has the chance to learn something new

my 2 cents,

Norbert

Am 12.02.2014 um 15:03 schrieb [hidden email]:

Norbert Hartl wrote:
Am 12.02.2014 um 11:44 schrieb Sven Van Caekenberghe [hidden email]:

  
#( 11 7 4 21 ) detectIndex: #even

    
I knew it makes sense to ask. Only slightly embarrasing :)
  
Thanks for asking. I learnt something new.
cheers -ben
Norbert

  
;-)

On 12 Feb 2014, at 12:37, Norbert Hartl [hidden email] wrote:

    
I just discovered that there is no method like

indexOf: aBlock

where the index of the element matching the block is returned. What would be the usual way to achieve this functionality?

Norbert


      
    

  



Reply | Threaded
Open this post in threaded view
|

Re: index of element matching block

PabloEstefo
In reply to this post by Ben Coman

On Feb 12, 2014, at 12:03, [hidden email] wrote:

Norbert Hartl wrote:
Am 12.02.2014 um 11:44 schrieb Sven Van Caekenberghe [hidden email]:

  
#( 11 7 4 21 ) detectIndex: #even

    
I knew it makes sense to ask. Only slightly embarrasing :)
  
Thanks for asking. I learnt something new.

+1

Thanks!

cheers -ben
Norbert

  
;-)

On 12 Feb 2014, at 12:37, Norbert Hartl [hidden email] wrote:

    
I just discovered that there is no method like

indexOf: aBlock

where the index of the element matching the block is returned. What would be the usual way to achieve this functionality?

Norbert