From: Daniel Pitts on
Kevin McMurtrie wrote:
> In article <vdfRm.35142$cd7.18472(a)newsfe04.iad>,
> Daniel Pitts <newsgroup.spamfilter(a)virtualinfinity.net> wrote:
>
>> Kevin McMurtrie wrote:
>>> In article <7nkah7F3luvvkU1(a)mid.individual.net>,
>>> Fencer <no.i.dont(a)want.mail.from.spammers.com> wrote:
>>>
>>>> Say I have a List<SomeClass> and now I want to loop through the list but
>>>> I am only interested in the String representation of the SomeClass objects.
>>>>
>>>> Do I have to do it like this:
>>>>
>>>> for (SomeClass inst : aListOfSomeClass) {
>>>> String str = inst.toString();
>>>> // Do something with str
>>>> }
>>>>
>>>> ?
>>>>
>>>> I don't really care about each instance objecct here, just the string
>>>> represenation of each instance, so is it possible to do something like
>>>> the following non-valid code (and here I imagine toString() being called
>>>> on each element):
>>>>
>>>> for (String str : aListOfSomeClass.toString()) {
>>>> // Do something with str
>>>> }
>>>>
>>>> Hope I made sense, thanks!
>>>>
>>>> - Fencer
>>> Java always has a hard way :)
>>>
>>>
>>> public class StringItr implements Iterable<String>
>>> {
>>> final Iterable m_target;
>> This should be an Iterable<?>
>
> It should have array support, JavaDocs, and proper spacing too but it's
> just free info on Usenet. I leave it to the viewer to add the finishing
> touches.
>
> [snip]
Finishing touches are one thing, broken code is another ;-).
I would advocate a different approach, which is basically a library for
providing an equivalent functionality to mapcar.

--
Daniel Pitts' Tech Blog: <http://virtualinfinity.net/wordpress/>
From: Arved Sandstrom on
Daniel Pitts wrote:
[ SNIP ]

> Finishing touches are one thing, broken code is another ;-).
> I would advocate a different approach, which is basically a library for
> providing an equivalent functionality to mapcar.
>
If and when Java gets lambdas I'd just make "map" a method in Collection.

AHS