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

lazy set?

3 replies
vpatryshev
Joined: 2009-02-16,
User offline. Last seen 1 year 24 weeks ago.
Hi,
I'm trying to figure out how come there are no lazy sets (as far as I know) in Scala, and whether anybody has a solution already.
See what I mean. There are Seq and Stream, which I would classify as lazy versions of lists. But I do not need a list, I need a set. 
In Java I can easily write stuff like
Set<Integer> N = new AbstractSet<Integer>() {   public Iterator<Integer> iterator() {    int i = 0;     public boolean hasNext() { return true;}    public Integer next() { return i++; }    ...  }   public int size() {    return Integer.MAX_VALUE;   }
}
Perfectly legal. And imagine the amazement of an ex-Javer when it turns out there's no such thing as AbstractSet.
Any ideas?
Thanks,-Vlad
Erik Engbrecht
Joined: 2008-12-19,
User offline. Last seen 3 years 18 weeks ago.
Re: lazy set?
There are three base traits for sets in Scala:scala.collection.Setscala.collection.immutable.Setscala.collection.mutable.Set
All of these can be treated as a base similar to AbstractSet, and the one you choose depends on the semantics you want (mutable, immutable, or don't care).  If you want to create a lazy set, then you probably want immutable, as laziness and mutability don't mix very well.
On Mon, Feb 16, 2009 at 2:38 AM, Vlad Patryshev <vpatryshev@gmail.com> wrote:
Hi,
I'm trying to figure out how come there are no lazy sets (as far as I know) in Scala, and whether anybody has a solution already.
See what I mean. There are Seq and Stream, which I would classify as lazy versions of lists. But I do not need a list, I need a set. 
In Java I can easily write stuff like
Set<Integer> N = new AbstractSet<Integer>() {   public Iterator<Integer> iterator() {    int i = 0;     public boolean hasNext() { return true;}    public Integer next() { return i++; }    ...  }   public int size() {    return Integer.MAX_VALUE;   }
}
Perfectly legal. And imagine the amazement of an ex-Javer when it turns out there's no such thing as AbstractSet.
Any ideas?
Thanks,-Vlad



--
http://erikengbrecht.blogspot.com/
vpatryshev
Joined: 2009-02-16,
User offline. Last seen 1 year 24 weeks ago.
Re: lazy set?
Oh. Sure that's what I should count on. Thanks!

2009/2/16 Erik Engbrecht <erik.engbrecht@gmail.com>
There are three base traits for sets in Scala:scala.collection.Setscala.collection.immutable.Setscala.collection.mutable.Set
All of these can be treated as a base similar to AbstractSet, and the one you choose depends on the semantics you want (mutable, immutable, or don't care).  If you want to create a lazy set, then you probably want immutable, as laziness and mutability don't mix very well.
On Mon, Feb 16, 2009 at 2:38 AM, Vlad Patryshev <vpatryshev@gmail.com> wrote:
Hi,
I'm trying to figure out how come there are no lazy sets (as far as I know) in Scala, and whether anybody has a solution already.
See what I mean. There are Seq and Stream, which I would classify as lazy versions of lists. But I do not need a list, I need a set. 
In Java I can easily write stuff like
Set<Integer> N = new AbstractSet<Integer>() {   public Iterator<Integer> iterator() {    int i = 0;     public boolean hasNext() { return true;}    public Integer next() { return i++; }    ...  }   public int size() {    return Integer.MAX_VALUE;   }
}
Perfectly legal. And imagine the amazement of an ex-Javer when it turns out there's no such thing as AbstractSet.
Any ideas?
Thanks,-Vlad



--
http://erikengbrecht.blogspot.com/



--
:)
-Vlad
malinova
Joined: 2010-11-01,
User offline. Last seen 1 year 48 weeks ago.
Высокий, косая

Высокий, косая сажень в плечах, артист в мундире, треуголке и ботфортах, с тяжелой тростью в руках удивительно походил на бронзового Петра работы скульптора Антокольского, что стоит на набережной Северной Двины в Архангельске - Похож, да

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