On 15 October 2011 11:49, Russel Winder <[email protected]> wrote:
> On Thu, 2011-10-13 at 14:04 +0100, Kevin Wright wrote:
> [ . . . ]
> >
> > I'd defy anyone to come up with a dynamically-typed equivalent to this
> > Scala snippet that's as simple, comprehensible, and as effortlessly
> > thread-safe:
> >
> >
> > val developers = employees collect { case d: Developer => d }
>
> How is this effortlessly thread safe unless each data structure has a
> lock and so you have whole data structure locking.
>
>
Simple, if employees has already been defined as:
val employees = Seq(employee1, employee2, employee3, ...)
Or similar, then extracting developers can't be anything *but* thread-safe -
such is the nature of immutable collections. Better yet, we could do this:
val employees = ParSeq(employee1, employee2, employee3, ...)
or
val employees = Seq(employee1, employee2, employee3, ...)
val developers = employees.par collect { case d: Developer => d }
and it's automatically run in parallel.
> To answer the challenge:
>
> Python:
>
> developers = [ e for e in employees if isinstance(e, Developer) ]
>
> Groovy:
>
> final developers = employees.filter { it instanceof Developer }
>
>
> which of course gives rise to the problem of what collect, filter, map,
> reduce, inject, etc. mean in each language, as each language that has
> them uses them with different semantics :-((
>
> --
> Russel.
>
> =============================================================================
> Dr Russel Winder t: +44 20 7585 2200 voip:
> sip:[email protected]
> 41 Buckmaster Road m: +44 7770 465 077 xmpp: [email protected]
> London SW11 1EN, UK w: www.russel.org.uk skype: russel_winder
>
--
Kevin Wright
mail: [email protected]
gtalk / msn : [email protected]
quora: http://www.quora.com/Kevin-Wright
google+: http://gplus.to/thecoda
<[email protected]>
twitter: @thecoda
vibe / skype: kev.lee.wright
steam: kev_lee_wright
"My point today is that, if we wish to count lines of code, we should not
regard them as "lines produced" but as "lines spent": the current
conventional wisdom is so foolish as to book that count on the wrong side of
the ledger" ~ Dijkstra
--
You received this message because you are subscribed to the Google Groups "The
Java Posse" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/javaposse?hl=en.