- About Scala
- Documentation
- Code Examples
- Software
- Scala Developers
lazy set?
Mon, 2009-02-16, 08:38
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
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
Mon, 2009-02-16, 19:27
#2
Re: lazy set?
Oh. Sure that's what I should count on. Thanks!
2009/2/16 Erik Engbrecht <erik.engbrecht@gmail.com>
--
:)
-Vlad
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
Sat, 2010-12-04, 11:16
#3
Высокий, косая
Высокий, косая сажень в плечах, артист в мундире, треуголке и ботфортах, с тяжелой тростью в руках удивительно походил на бронзового Петра работы скульптора Антокольского, что стоит на набережной Северной Двины в Архангельске - Похож, да
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:
--
http://erikengbrecht.blogspot.com/