- About Scala
- Documentation
- Code Examples
- Software
- Scala Developers
Applying a predicate between elements of two collections
Tue, 2010-06-29, 10:21
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
Tue, 2010-06-29, 12:17
#2
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
Tue, 2010-06-29, 12:27
#3
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
Tue, 2010-06-29, 12:37
#4
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
>>
Tue, 2010-06-29, 14:17
#5
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
>>>
>
Tue, 2010-06-29, 15:17
#6
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:
--
Daniel C. Sobral
I travel to the future all the time.
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.
Tue, 2010-06-29, 15:17
#7
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
> >
>
>
>
Tue, 2010-06-29, 15:27
#8
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:
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.
Tue, 2010-06-29, 15:37
#9
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 ;-)
Tue, 2010-06-29, 15:57
#10
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>
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
Tue, 2010-06-29, 16:07
#11
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:
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
Tue, 2010-06-29, 17:47
#12
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:
--
Daniel C. Sobral
I travel to the future all the time.
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.
Tue, 2010-06-29, 17:57
#13
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:
--
Daniel C. Sobral
I travel to the future all the time.
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.
Tue, 2010-06-29, 18:27
#14
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
>
>
>
>
Tue, 2010-06-29, 18:37
#15
Re: Applying a predicate between elements of two collections
Dennis Haupt schrieb:
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">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.may i ask what in the world could be the reason for someone to actually want to implement such an algorithm?
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 SobralAn: 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, Iwouldlike 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 secondList.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 atleastone 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 whetherthereis such a relationship between two collections? I realize there is intersect, but it does only check for identity andnotfor a predicate. Cheers Dan
Tue, 2010-06-29, 18:57
#16
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.
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.
Tue, 2010-06-29, 21:57
#17
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>
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.
Tue, 2010-06-29, 22:07
#18
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>
--
Daniel C. Sobral
I travel to the future all the time.
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.
Tue, 2010-06-29, 23:17
#19
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:
--
Kevin Wright
mail/google talk: kev.lee.wright@gmail.com
wave: kev.lee.wright@googlewave.com
skype: kev.lee.wright
twitter: @thecoda
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
Tue, 2010-06-29, 23:37
#20
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
Wed, 2010-06-30, 00:17
#21
Re: Re: Applying a predicate between elements of two collectio
:)
On 29 June 2010 23:23, Jason Zaugg <jzaugg@gmail.com> wrote:
--
Kevin Wright
mail/google talk: kev.lee.wright@gmail.com
wave: kev.lee.wright@googlewave.com
skype: kev.lee.wright
twitter: @thecoda
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
Wed, 2010-06-30, 11:07
#22
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.
(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.
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