This page is no longer maintained — Please continue to the home page at www.scala-lang.org

Applying a predicate between elements of two collections

22 replies
Daniel Degrandi
Joined: 2010-05-10,
User offline. Last seen 42 years 45 weeks ago.

Hi,

I would like to know if there is a better (faster) way to check for the
following:

I have 2 Lists, both contain an arbitrary number of manifests. Now, I
would like to check whether the first List contains at least one
manifest of a type that is a subtype of at least one manifested type of
the second List.

Example:

trait Foo
trait Bar extends Foo
trait XY

val list1 = List(manifest[Foo], manifest[Bar], manifest[XY])
val list 2 = List(manifest[Int], manifest[String], manifest[Symbol],
manifest[Foo])

so to check whether at least one manifest of list1 is a subtype of at
least one manifest of list 2 I came up to this:

val a = list1.exists(m1 => list2.exists(m1 <:< _))

result: true

Similar things may be done with "map" and "filter"

This works, but looks ugly with the nested "exists". Is there a perhaps
more idiomatic way to do it?

In general: Do we need a method in the collections that check whether
there is such a relationship between two collections?
I realize there is intersect, but it does only check for identity and
not for a predicate.

Cheers
Dan

milessabin
Joined: 2008-08-11,
User offline. Last seen 33 weeks 3 days ago.
Re: Applying a predicate between elements of two collections

On Tue, Jun 29, 2010 at 10:21 AM, Daniel Degrandi
wrote:
> I would like to know if there is a better (faster) way to check for the
> following:
>
> I have 2 Lists, both contain an arbitrary number of manifests. Now, I would
> like to check whether the first List contains at least one manifest of a
> type that is a subtype of at least one manifested type of the second List.
>
> Example:
>
> trait Foo
> trait Bar extends Foo
> trait XY
>
> val list1 = List(manifest[Foo], manifest[Bar], manifest[XY])
> val list 2 = List(manifest[Int], manifest[String], manifest[Symbol],
> manifest[Foo])
>
> so to check whether at least one manifest of list1 is a subtype of at least
> one manifest of list 2 I came up to this:
>
> val a = list1.exists(m1 => list2.exists(m1 <:< _))
>
> result: true
>
> Similar things may be done with "map" and "filter"
>
> This works, but looks ugly with the nested "exists". Is there a perhaps more
> idiomatic way to do it?

I don't know about "more idiomatic", but the following is certainly
more symmetrical,

val perms = for (x <- list1 ; y <- list2) yield (x, y)
perms exists { case (m1, m2) => m1 <:< m2 }

Cheers,

Miles

pkolaczk
Joined: 2010-01-14,
User offline. Last seen 2 years 38 weeks ago.
Re: Applying a predicate between elements of two collections

W dniu 2010-06-29 12:14, Miles Sabin pisze:
> On Tue, Jun 29, 2010 at 10:21 AM, Daniel Degrandi
> wrote:
>> I would like to know if there is a better (faster) way to check for the
>> following:
>>
>> I have 2 Lists, both contain an arbitrary number of manifests. Now, I would
>> like to check whether the first List contains at least one manifest of a
>> type that is a subtype of at least one manifested type of the second List.
>>
>> Example:
>>
>> trait Foo
>> trait Bar extends Foo
>> trait XY
>>
>> val list1 = List(manifest[Foo], manifest[Bar], manifest[XY])
>> val list 2 = List(manifest[Int], manifest[String], manifest[Symbol],
>> manifest[Foo])
>>
>> so to check whether at least one manifest of list1 is a subtype of at least
>> one manifest of list 2 I came up to this:
>>
>> val a = list1.exists(m1 => list2.exists(m1<:< _))
>>
>> result: true
>>
>> Similar things may be done with "map" and "filter"
>>
>> This works, but looks ugly with the nested "exists". Is there a perhaps more
>> idiomatic way to do it?
>
> I don't know about "more idiomatic", but the following is certainly
> more symmetrical,
>
> val perms = for (x<- list1 ; y<- list2) yield (x, y)
> perms exists { case (m1, m2) => m1<:< m2 }
>

And even shorter:

!(for (x <- list1; y <- list2 if x <:< y) yield 1).isEmpty

Cheers,
Piotr

Jason Zaugg
Joined: 2009-05-18,
User offline. Last seen 38 weeks 5 days ago.
Re: Re: Applying a predicate between elements of two collectio

And even lazier:

!(for (x <- list1.iterator; y <- list2.iterator if x <:< y) yield ()).isEmpty

-jason

2010/6/29 Piotr Kołaczkowski :
> And even shorter:
>
> !(for (x <- list1; y <- list2 if x <:< y) yield 1).isEmpty

Daniel Degrandi
Joined: 2010-05-10,
User offline. Last seen 42 years 45 weeks ago.
Re: Re: Applying a predicate between elements of two collection

Thanks guys,

what about .. and even faster?

I'm a bit concerned about performance because it could be something that
gets tested quite often.

Dan

Jason Zaugg schrieb:
> And even lazier:
>
> !(for (x <- list1.iterator; y <- list2.iterator if x <:< y) yield ()).isEmpty
>
> -jason
>
> 2010/6/29 Piotr Kołaczkowski :
>
>> And even shorter:
>>
>> !(for (x <- list1; y <- list2 if x <:< y) yield 1).isEmpty
>>

Willis Blackburn
Joined: 2010-06-16,
User offline. Last seen 42 years 45 weeks ago.
Re: Re: Applying a predicate between elements of two collection

How large do you expect your lists to be?

W

Sent from my iPhone

On Jun 29, 2010, at 7:23 AM, Daniel Degrandi wrote:

> Thanks guys,
>
> what about .. and even faster?
>
> I'm a bit concerned about performance because it could be something that gets tested quite often.
>
> Dan
>
> Jason Zaugg schrieb:
>> And even lazier:
>>
>> !(for (x <- list1.iterator; y <- list2.iterator if x <:< y) yield ()).isEmpty
>>
>> -jason
>>
>> 2010/6/29 Piotr Kołaczkowski :
>>
>>> And even shorter:
>>>
>>> !(for (x <- list1; y <- list2 if x <:< y) yield 1).isEmpty
>>>
>

dcsobral
Joined: 2009-04-23,
User offline. Last seen 38 weeks 5 days ago.
Re: Applying a predicate between elements of two collections
Let's try this:
val map1 = list1 groupBy (_##)val map2 = list2 groupBy (_##)map1.keySet exists (hash => map1(hash) exists (man => map2 get hash exists (_ exists (man ==))))
It should be faster, though you'll probably hate all the nested exists. :-)
On Tue, Jun 29, 2010 at 6:21 AM, Daniel Degrandi <Daniel.Degrandi@uni-duesseldorf.de> wrote:
Hi,

I would like to know if there is a better (faster) way to check for the following:

I have 2 Lists, both contain an arbitrary number of manifests. Now, I would like to check whether the first List contains at least one manifest of a type that is a subtype of at least one manifested type of the second List.

Example:

trait Foo
trait Bar extends Foo
trait XY

val list1 = List(manifest[Foo], manifest[Bar], manifest[XY])
val list 2 = List(manifest[Int], manifest[String], manifest[Symbol], manifest[Foo])

so to check whether at least one manifest of list1 is a subtype of at least one manifest of list 2 I came up to this:

val a = list1.exists(m1 => list2.exists(m1 <:< _))

result: true

Similar things may be done with "map" and "filter"

This works, but looks ugly with the nested "exists". Is there a perhaps more idiomatic way to do it?

In general: Do we need a method in the collections that check whether there is such a relationship between two collections?
I realize there is intersect, but it does only check for identity and not for a predicate.

Cheers
Dan



--
Daniel C. Sobral

I travel to the future all the time.
H-star Development
Joined: 2010-04-14,
User offline. Last seen 2 years 26 weeks ago.
Re: Applying a predicate between elements of two collections

may i ask what in the world could be the reason for someone to actually want to implement such an algorithm?

-------- Original-Nachricht --------
> Datum: Tue, 29 Jun 2010 11:07:42 -0300
> Von: Daniel Sobral
> An: Daniel Degrandi
> CC: scala-user@listes.epfl.ch
> Betreff: Re: [scala-user] Applying a predicate between elements of two collections

> Let's try this:
>
> val map1 = list1 groupBy (_##)
> val map2 = list2 groupBy (_##)
> map1.keySet exists (hash => map1(hash) exists (man => map2 get hash exists
> (_ exists (man ==))))
>
> It should be faster, though you'll probably hate all the nested exists.
> :-)
>
> On Tue, Jun 29, 2010 at 6:21 AM, Daniel Degrandi <
> Daniel.Degrandi@uni-duesseldorf.de> wrote:
>
> > Hi,
> >
> > I would like to know if there is a better (faster) way to check for the
> > following:
> >
> > I have 2 Lists, both contain an arbitrary number of manifests. Now, I
> would
> > like to check whether the first List contains at least one manifest of a
> > type that is a subtype of at least one manifested type of the second
> List.
> >
> > Example:
> >
> > trait Foo
> > trait Bar extends Foo
> > trait XY
> >
> > val list1 = List(manifest[Foo], manifest[Bar], manifest[XY])
> > val list 2 = List(manifest[Int], manifest[String], manifest[Symbol],
> > manifest[Foo])
> >
> > so to check whether at least one manifest of list1 is a subtype of at
> least
> > one manifest of list 2 I came up to this:
> >
> > val a = list1.exists(m1 => list2.exists(m1 <:< _))
> >
> > result: true
> >
> > Similar things may be done with "map" and "filter"
> >
> > This works, but looks ugly with the nested "exists". Is there a perhaps
> > more idiomatic way to do it?
> >
> > In general: Do we need a method in the collections that check whether
> there
> > is such a relationship between two collections?
> > I realize there is intersect, but it does only check for identity and
> not
> > for a predicate.
> >
> > Cheers
> > Dan
> >
>
>
>

bmaso
Joined: 2009-10-04,
User offline. Last seen 2 years 40 weeks ago.
Re: Applying a predicate between elements of two collections
I see how using exists would be a lot faster.... But this example doesn't actually solve the OP's proposed problem: finding any members of list2 that are *subtypes* of any members in list1.

I think this is maybe a general-purpose, efficient "is the intersection non-empty" implementation.

Brian Maso

On Tue, Jun 29, 2010 at 7:07 AM, Daniel Sobral <dcsobral@gmail.com> wrote:
Let's try this:
val map1 = list1 groupBy (_##)val map2 = list2 groupBy (_##)map1.keySet exists (hash => map1(hash) exists (man => map2 get hash exists (_ exists (man ==))))
It should be faster, though you'll probably hate all the nested exists. :-)
On Tue, Jun 29, 2010 at 6:21 AM, Daniel Degrandi <Daniel.Degrandi@uni-duesseldorf.de> wrote:
Hi,

I would like to know if there is a better (faster) way to check for the following:

I have 2 Lists, both contain an arbitrary number of manifests. Now, I would like to check whether the first List contains at least one manifest of a type that is a subtype of at least one manifested type of the second List.

Example:

trait Foo
trait Bar extends Foo
trait XY

val list1 = List(manifest[Foo], manifest[Bar], manifest[XY])
val list 2 = List(manifest[Int], manifest[String], manifest[Symbol], manifest[Foo])

so to check whether at least one manifest of list1 is a subtype of at least one manifest of list 2 I came up to this:

val a = list1.exists(m1 => list2.exists(m1 <:< _))

result: true

Similar things may be done with "map" and "filter"

This works, but looks ugly with the nested "exists". Is there a perhaps more idiomatic way to do it?

In general: Do we need a method in the collections that check whether there is such a relationship between two collections?
I realize there is intersect, but it does only check for identity and not for a predicate.

Cheers
Dan



--
Daniel C. Sobral

I travel to the future all the time.

Daniel Degrandi
Joined: 2010-05-10,
User offline. Last seen 42 years 45 weeks ago.
Re: Applying a predicate between elements of two collections

Daniel Sobral schrieb:
> Let's try this:
>
> val map1 = list1 groupBy (_##)
> val map2 = list2 groupBy (_##)
> map1.keySet exists (hash => map1(hash) exists (man => map2 get hash
> exists (_ exists (man ==))))
>
> It should be faster, though you'll probably hate all the nested
> exists. :-)

Looks like Assembler to me. so....... No, but thanks anyway ;-)

bmaso
Joined: 2009-10-04,
User offline. Last seen 2 years 40 weeks ago.
Re: Re: Applying a predicate between elements of two collectio
How is list1.iterator going to behave vs. list1.view in Jason's solution (below)? I'm not really clear on the lazy behavior differences between "view" and "iterator", but since "view" is guaranteed to be non-strict, while Iterator is not, wouldn't "view" be better?

Brian Maso

2010/6/29 Jason Zaugg <jzaugg@gmail.com>
And even lazier:

!(for (x <- list1.iterator; y <- list2.iterator if x <:< y) yield ()).isEmpty

-jason

2010/6/29 Piotr Kołaczkowski <pkolaczk@elka.pw.edu.pl>:
> And even shorter:
>
> !(for (x <- list1; y <- list2 if x <:< y) yield 1).isEmpty

James Iry
Joined: 2008-08-19,
User offline. Last seen 1 year 23 weeks ago.
Re: Re: Applying a predicate between elements of two collectio
Because you are using (unordered) lists any intersection-like computation is going to be average case O(n^2) or worse.  Jason's lazy version helps because it can terminate early, but it's still O(n^2) worst and average.   If one list will be reused often then doing a topological sort might also help a little but still can't change the n^2 efficiency.
If one list is reused often and you tend to see some of the same manifests over and over the it might be worth turning that list into a set and doing some dynamic programming.  You do a Set#get() to see if the manifest is directly in there. If not you use a linear search based on subtype checking.  If found, you add the manifest to the set so that the next get() of the same manifest will find it without the linear search.

On Tue, Jun 29, 2010 at 4:23 AM, Daniel Degrandi <Daniel.Degrandi@uni-duesseldorf.de> wrote:
Thanks guys,

what about .. and even faster?

I'm a bit concerned about performance because it could be something that gets tested quite often.

Dan

Jason Zaugg schrieb:
And even lazier:

!(for (x <- list1.iterator; y <- list2.iterator if x <:< y) yield ()).isEmpty

-jason

2010/6/29 Piotr Kołaczkowski <pkolaczk@elka.pw.edu.pl>:
 
And even shorter:

!(for (x <- list1; y <- list2 if x <:< y) yield 1).isEmpty
   

dcsobral
Joined: 2009-04-23,
User offline. Last seen 38 weeks 5 days ago.
Re: Applying a predicate between elements of two collections
Avoiding quadratic complexity.

On Tue, Jun 29, 2010 at 11:12 AM, Dennis Haupt <h-star@gmx.de> wrote:
may i ask what in the world could be the reason for someone to actually want to implement such an algorithm?

-------- Original-Nachricht --------
> Datum: Tue, 29 Jun 2010 11:07:42 -0300
> Von: Daniel Sobral <dcsobral@gmail.com>
> An: Daniel Degrandi <Daniel.Degrandi@uni-duesseldorf.de>
> CC: scala-user@listes.epfl.ch
> Betreff: Re: [scala-user] Applying a predicate between elements of two        collections

> Let's try this:
>
> val map1 = list1 groupBy (_##)
> val map2 = list2 groupBy (_##)
> map1.keySet exists (hash => map1(hash) exists (man => map2 get hash exists
> (_ exists (man ==))))
>
> It should be faster, though you'll probably hate all the nested exists.
> :-)
>
> On Tue, Jun 29, 2010 at 6:21 AM, Daniel Degrandi <
> Daniel.Degrandi@uni-duesseldorf.de> wrote:
>
> > Hi,
> >
> > I would like to know if there is a better (faster) way to check for the
> > following:
> >
> > I have 2 Lists, both contain an arbitrary number of manifests. Now, I
> would
> > like to check whether the first List contains at least one manifest of a
> > type that is a subtype of at least one manifested type of the second
> List.
> >
> > Example:
> >
> > trait Foo
> > trait Bar extends Foo
> > trait XY
> >
> > val list1 = List(manifest[Foo], manifest[Bar], manifest[XY])
> > val list 2 = List(manifest[Int], manifest[String], manifest[Symbol],
> > manifest[Foo])
> >
> > so to check whether at least one manifest of list1 is a subtype of at
> least
> > one manifest of list 2 I came up to this:
> >
> > val a = list1.exists(m1 => list2.exists(m1 <:< _))
> >
> > result: true
> >
> > Similar things may be done with "map" and "filter"
> >
> > This works, but looks ugly with the nested "exists". Is there a perhaps
> > more idiomatic way to do it?
> >
> > In general: Do we need a method in the collections that check whether
> there
> > is such a relationship between two collections?
> > I realize there is intersect, but it does only check for identity and
> not
> > for a predicate.
> >
> > Cheers
> > Dan
> >
>
>
>
> --
> Daniel C. Sobral
>
> I travel to the future all the time.

--
GMX DSL: Internet-, Telefon- und Handy-Flat ab 19,99 EUR/mtl.
Bis zu 150 EUR Startguthaben inklusive! http://portal.gmx.net/de/go/dsl



--
Daniel C. Sobral

I travel to the future all the time.
dcsobral
Joined: 2009-04-23,
User offline. Last seen 38 weeks 5 days ago.
Re: Applying a predicate between elements of two collections
Oh, duh.
Well... would could always get the hash of the parent class closer to Object (or, if they all share a common superclass, the children of it). Also, I note one must traverse both map1.keySet and map2.keySet, because A <:< B does not imply B <: A. Still, doable. For very large lists and time critical code, I think it's worth consideration.

On Tue, Jun 29, 2010 at 11:26 AM, Brian Maso <brian@blumenfeld-maso.com> wrote:
I see how using exists would be a lot faster.... But this example doesn't actually solve the OP's proposed problem: finding any members of list2 that are *subtypes* of any members in list1.

I think this is maybe a general-purpose, efficient "is the intersection non-empty" implementation.

Brian Maso

On Tue, Jun 29, 2010 at 7:07 AM, Daniel Sobral <dcsobral@gmail.com> wrote:
Let's try this:
val map1 = list1 groupBy (_##)val map2 = list2 groupBy (_##)map1.keySet exists (hash => map1(hash) exists (man => map2 get hash exists (_ exists (man ==))))
It should be faster, though you'll probably hate all the nested exists. :-)
On Tue, Jun 29, 2010 at 6:21 AM, Daniel Degrandi <Daniel.Degrandi@uni-duesseldorf.de> wrote:
Hi,

I would like to know if there is a better (faster) way to check for the following:

I have 2 Lists, both contain an arbitrary number of manifests. Now, I would like to check whether the first List contains at least one manifest of a type that is a subtype of at least one manifested type of the second List.

Example:

trait Foo
trait Bar extends Foo
trait XY

val list1 = List(manifest[Foo], manifest[Bar], manifest[XY])
val list 2 = List(manifest[Int], manifest[String], manifest[Symbol], manifest[Foo])

so to check whether at least one manifest of list1 is a subtype of at least one manifest of list 2 I came up to this:

val a = list1.exists(m1 => list2.exists(m1 <:< _))

result: true

Similar things may be done with "map" and "filter"

This works, but looks ugly with the nested "exists". Is there a perhaps more idiomatic way to do it?

In general: Do we need a method in the collections that check whether there is such a relationship between two collections?
I realize there is intersect, but it does only check for identity and not for a predicate.

Cheers
Dan



--
Daniel C. Sobral

I travel to the future all the time.




--
Daniel C. Sobral

I travel to the future all the time.
H-star Development
Joined: 2010-04-14,
User offline. Last seen 2 years 26 weeks ago.
Re: Applying a predicate between elements of two collections

i meant the "manifest subclass"-part

Daniel Sobral schrieb:
> Avoiding quadratic complexity.
>
> On Tue, Jun 29, 2010 at 11:12 AM, Dennis Haupt > wrote:
>
> may i ask what in the world could be the reason for someone to
> actually want to implement such an algorithm?
>
> -------- Original-Nachricht --------
> > Datum: Tue, 29 Jun 2010 11:07:42 -0300
> > Von: Daniel Sobral >
> > An: Daniel Degrandi >
> > CC: scala-user@listes.epfl.ch
> > Betreff: Re: [scala-user] Applying a predicate between elements
> of two collections
>
> > Let's try this:
> >
> > val map1 = list1 groupBy (_##)
> > val map2 = list2 groupBy (_##)
> > map1.keySet exists (hash => map1(hash) exists (man => map2 get
> hash exists
> > (_ exists (man ==))))
> >
> > It should be faster, though you'll probably hate all the nested
> exists.
> > :-)
> >
> > On Tue, Jun 29, 2010 at 6:21 AM, Daniel Degrandi <
> > Daniel.Degrandi@uni-duesseldorf.de
> > wrote:
> >
> > > Hi,
> > >
> > > I would like to know if there is a better (faster) way to
> check for the
> > > following:
> > >
> > > I have 2 Lists, both contain an arbitrary number of manifests.
> Now, I
> > would
> > > like to check whether the first List contains at least one
> manifest of a
> > > type that is a subtype of at least one manifested type of the
> second
> > List.
> > >
> > > Example:
> > >
> > > trait Foo
> > > trait Bar extends Foo
> > > trait XY
> > >
> > > val list1 = List(manifest[Foo], manifest[Bar], manifest[XY])
> > > val list 2 = List(manifest[Int], manifest[String],
> manifest[Symbol],
> > > manifest[Foo])
> > >
> > > so to check whether at least one manifest of list1 is a
> subtype of at
> > least
> > > one manifest of list 2 I came up to this:
> > >
> > > val a = list1.exists(m1 => list2.exists(m1 <:< _))
> > >
> > > result: true
> > >
> > > Similar things may be done with "map" and "filter"
> > >
> > > This works, but looks ugly with the nested "exists". Is there
> a perhaps
> > > more idiomatic way to do it?
> > >
> > > In general: Do we need a method in the collections that check
> whether
> > there
> > > is such a relationship between two collections?
> > > I realize there is intersect, but it does only check for
> identity and
> > not
> > > for a predicate.
> > >
> > > Cheers
> > > Dan
> > >
> >
> >
> >
> > --
> > Daniel C. Sobral
> >
> > I travel to the future all the time.
>
> --
> GMX DSL: Internet-, Telefon- und Handy-Flat ab 19,99 EUR/mtl.
> Bis zu 150 EUR Startguthaben inklusive!
> http://portal.gmx.net/de/go/dsl
>
>
>
>

Daniel Degrandi
Joined: 2010-05-10,
User offline. Last seen 42 years 45 weeks ago.
Re: Applying a predicate between elements of two collections
Dennis Haupt schrieb:
20100629141230 [dot] 190480 [at] gmx [dot] net" type="cite">
may i ask what in the world could be the reason for someone to actually want to implement such an algorithm?
  
Oh well... this is not easily explained. It's part of a rather experimental piece of code I'm playing with in my free time. Basically it's a graphical representation of arbitrary data, with the aim to apply functions on data using a GUI and improve data sharing between different programs.
Since I'm working a lot with type parameters i need a way to emulate type safety at runtime.



20100629141230 [dot] 190480 [at] gmx [dot] net" type="cite">
-------- Original-Nachricht --------
  
Datum: Tue, 29 Jun 2010 11:07:42 -0300
Von: Daniel Sobral 
An: Daniel Degrandi 
CC: scala-user@listes.epfl.ch
Betreff: Re: [scala-user] Applying a predicate between elements of two 	collections
    
  
Let's try this:

val map1 = list1 groupBy (_##)
val map2 = list2 groupBy (_##)
map1.keySet exists (hash => map1(hash) exists (man => map2 get hash exists
(_ exists (man ==))))

It should be faster, though you'll probably hate all the nested exists.
:-)

On Tue, Jun 29, 2010 at 6:21 AM, Daniel Degrandi <
Daniel.Degrandi@uni-duesseldorf.de> wrote:

    
Hi,

I would like to know if there is a better (faster) way to check for the
following:

I have 2 Lists, both contain an arbitrary number of manifests. Now, I
      
would
    
like to check whether the first List contains at least one manifest of a
type that is a subtype of at least one manifested type of the second
      
List.
    
Example:

trait Foo
trait Bar extends Foo
trait XY

val list1 = List(manifest[Foo], manifest[Bar], manifest[XY])
val list 2 = List(manifest[Int], manifest[String], manifest[Symbol],
manifest[Foo])

so to check whether at least one manifest of list1 is a subtype of at
      
least
    
one manifest of list 2 I came up to this:

val a = list1.exists(m1 => list2.exists(m1 <:< _))

result: true

Similar things may be done with "map" and "filter"

This works, but looks ugly with the nested "exists". Is there a perhaps
more idiomatic way to do it?

In general: Do we need a method in the collections that check whether
      
there
    
is such a relationship between two collections?
I realize there is intersect, but it does only check for identity and
      
not
    
for a predicate.

Cheers
Dan

      
Chris Marshall
Joined: 2009-06-17,
User offline. Last seen 44 weeks 3 days ago.
RE: Re: Applying a predicate between elements of two collectio
I'm surprised at you Jason!
scala> import scalaz._; import Scalaz._import scalaz._import Scalaz._
scala> list1 <|*|> list2 exists { case (m1, m2)=> m1 <:< m2 }

Chris
> Date: Tue, 29 Jun 2010 13:17:06 +0200
> Subject: Re: [scala-user] Re: Applying a predicate between elements of two collections
> From: jzaugg@gmail.com
> To: pkolaczk@elka.pw.edu.pl
> CC: scala-user@listes.epfl.ch; public-Daniel.Degrandi-4bfl1RV3iZDOEhgYWvzSCYQuADTiUCJX@lo.gmane.org; public-scala-user-soYaJrOCGFRsFbksJNLsAg@lo.gmane.org
>
> And even lazier:
>
> !(for (x <- list1.iterator; y <- list2.iterator if x <:< y) yield ()).isEmpty
>
> -jason
>
> 2010/6/29 Piotr Kołaczkowski <pkolaczk@elka.pw.edu.pl>:
> > And even shorter:
> >
> > !(for (x <- list1; y <- list2 if x <:< y) yield 1).isEmpty

Get a new e-mail account with Hotmail - Free. Sign-up now.
bmaso
Joined: 2009-10-04,
User offline. Last seen 2 years 40 weeks ago.
Re: Re: Applying a predicate between elements of two collectio
Someone just *has got* to write the definitive guide to scalaz. I suspect pretty much anything I feel like doing in Scala has been reduced to a single operator in there somewhere.

Brian Maso

2010/6/29 christopher marshall <oxbow_lakes@hotmail.com>
I'm surprised at you Jason!
scala> import scalaz._; import Scalaz._import scalaz._import Scalaz._
scala> list1 <|*|> list2 exists { case (m1, m2)=> m1 <:< m2 }

Chris
> Date: Tue, 29 Jun 2010 13:17:06 +0200
> Subject: Re: [scala-user] Re: Applying a predicate between elements of two collections
> From: jzaugg@gmail.com
> To: pkolaczk@elka.pw.edu.pl
> CC: scala-user@listes.epfl.ch; public-Daniel.Degrandi-4bfl1RV3iZDOEhgYWvzSCYQuADTiUCJX@lo.gmane.org; public-scala-user-soYaJrOCGFRsFbksJNLsAg@lo.gmane.org
>
> And even lazier:
>
> !(for (x <- list1.iterator; y <- list2.iterator if x <:< y) yield ()).isEmpty
>
> -jason
>
> 2010/6/29 Piotr Kołaczkowski <pkolaczk@elka.pw.edu.pl>:
> > And even shorter:
> >
> > !(for (x <- list1; y <- list2 if x <:< y) yield 1).isEmpty

Get a new e-mail account with Hotmail - Free. Sign-up now.

dcsobral
Joined: 2009-04-23,
User offline. Last seen 38 weeks 5 days ago.
Re: Re: Applying a predicate between elements of two collectio
I heard the next version is really cool, but the evaluate-program-termination operator is giving them problem. :-)

2010/6/29 Brian Maso <brian@blumenfeld-maso.com>
Someone just *has got* to write the definitive guide to scalaz. I suspect pretty much anything I feel like doing in Scala has been reduced to a single operator in there somewhere.

Brian Maso

2010/6/29 christopher marshall <oxbow_lakes@hotmail.com>
I'm surprised at you Jason!
scala> import scalaz._; import Scalaz._import scalaz._import Scalaz._
scala> list1 <|*|> list2 exists { case (m1, m2)=> m1 <:< m2 }

Chris
> Date: Tue, 29 Jun 2010 13:17:06 +0200
> Subject: Re: [scala-user] Re: Applying a predicate between elements of two collections
> From: jzaugg@gmail.com
> To: pkolaczk@elka.pw.edu.pl
> CC: scala-user@listes.epfl.ch; public-Daniel.Degrandi-4bfl1RV3iZDOEhgYWvzSCYQuADTiUCJX@lo.gmane.org; public-scala-user-soYaJrOCGFRsFbksJNLsAg@lo.gmane.org
>
> And even lazier:
>
> !(for (x <- list1.iterator; y <- list2.iterator if x <:< y) yield ()).isEmpty
>
> -jason
>
> 2010/6/29 Piotr Kołaczkowski <pkolaczk@elka.pw.edu.pl>:
> > And even shorter:
> >
> > !(for (x <- list1; y <- list2 if x <:< y) yield 1).isEmpty

Get a new e-mail account with Hotmail - Free. Sign-up now.




--
Daniel C. Sobral

I travel to the future all the time.
Kevin Wright 2
Joined: 2010-05-30,
User offline. Last seen 26 weeks 4 days ago.
Re: Re: Applying a predicate between elements of two collectio
I just want a list of all the non-ASCII operators, something to throw into mailing list discussions :)


On 29 June 2010 21:55, Daniel Sobral <dcsobral@gmail.com> wrote:
I heard the next version is really cool, but the evaluate-program-termination operator is giving them problem. :-)

2010/6/29 Brian Maso <brian@blumenfeld-maso.com>
Someone just *has got* to write the definitive guide to scalaz. I suspect pretty much anything I feel like doing in Scala has been reduced to a single operator in there somewhere.

Brian Maso

2010/6/29 christopher marshall <oxbow_lakes@hotmail.com>
I'm surprised at you Jason!
scala> import scalaz._; import Scalaz._import scalaz._import Scalaz._
scala> list1 <|*|> list2 exists { case (m1, m2)=> m1 <:< m2 }

Chris
> Date: Tue, 29 Jun 2010 13:17:06 +0200
> Subject: Re: [scala-user] Re: Applying a predicate between elements of two collections
> From: jzaugg@gmail.com
> To: pkolaczk@elka.pw.edu.pl
> CC: scala-user@listes.epfl.ch; public-Daniel.Degrandi-4bfl1RV3iZDOEhgYWvzSCYQuADTiUCJX@lo.gmane.org; public-scala-user-soYaJrOCGFRsFbksJNLsAg@lo.gmane.org
>
> And even lazier:
>
> !(for (x <- list1.iterator; y <- list2.iterator if x <:< y) yield ()).isEmpty
>
> -jason
>
> 2010/6/29 Piotr Kołaczkowski <pkolaczk@elka.pw.edu.pl>:
> > And even shorter:
> >
> > !(for (x <- list1; y <- list2 if x <:< y) yield 1).isEmpty

Get a new e-mail account with Hotmail - Free. Sign-up now.




--
Daniel C. Sobral

I travel to the future all the time.



--
Kevin Wright

mail/google talk: kev.lee.wright@gmail.com
wave: kev.lee.wright@googlewave.com
skype: kev.lee.wright
twitter: @thecoda

Jason Zaugg
Joined: 2009-05-18,
User offline. Last seen 38 weeks 5 days ago.
Re: Re: Applying a predicate between elements of two collectio

Oh fine...

(list1 ⊛ list2)(_ <:< _) ∋ true

2010/6/29 christopher marshall :
> I'm surprised at you Jason!
> scala> import scalaz._; import Scalaz._
> import scalaz._
> import Scalaz._
> scala> list1 <|*|> list2 exists { case (m1, m2)=> m1 <:< m2 }
>
> Chris

Kevin Wright 2
Joined: 2010-05-30,
User offline. Last seen 26 weeks 4 days ago.
Re: Re: Applying a predicate between elements of two collectio
:)

On 29 June 2010 23:23, Jason Zaugg <jzaugg@gmail.com> wrote:
Oh fine...

(list1 ⊛ list2)(_ <:< _) ∋ true

2010/6/29 christopher marshall <oxbow_lakes@hotmail.com>:
> I'm surprised at you Jason!
> scala> import scalaz._; import Scalaz._
> import scalaz._
> import Scalaz._
> scala> list1 <|*|> list2 exists { case (m1, m2)=> m1 <:< m2 }
>
> Chris



--
Kevin Wright

mail/google talk: kev.lee.wright@gmail.com
wave: kev.lee.wright@googlewave.com
skype: kev.lee.wright
twitter: @thecoda

Chris Marshall
Joined: 2009-06-17,
User offline. Last seen 44 weeks 3 days ago.
RE: Re: Applying a predicate between elements of two collectio
Or for extra ASCII fun:
(list1 |@| list2)(_ <:< _) reduceLeft (_ || _)

> Date: Wed, 30 Jun 2010 00:23:22 +0200
> Subject: Re: [scala-user] Re: Applying a predicate between elements of two collections
> From: jzaugg@gmail.com
> To: oxbow_lakes@hotmail.com
> CC: pkolaczk@elka.pw.edu.pl; scala-user@listes.epfl.ch; public-daniel.degrandi-4bfl1rv3izdoehgywvzscyquadtiucjx@lo.gmane.org; public-scala-user-soyajrocgfrsfbksjnlsag@lo.gmane.org
>
> Oh fine...
>
> (list1 ⊛ list2)(_ <:< _) ∋ true
>


Get a free e-mail account with Hotmail. Sign-up now.

Copyright © 2012 École Polytechnique Fédérale de Lausanne (EPFL), Lausanne, Switzerland