Scala: convert a return type into a custom trait?

Figured it out. Took me a few tries to understand: object Increment{ implicit def convert( input:IteratorString ) = new Increment{ def next() = input next def hasNext() = input hasNext } } and I'm done. So amazingly short.

Probably a good idea to call the method iterator2increment – oxbow_lakes Aug 16 '10 at 12:08.

I don't think that this is possible without playing tricks. A mixin inheritance happens at compile time, when it can be type-checked statically, and it is always targeted at another class, trait, etc. Here you try to tack a trait on an existing object "on the fly" at runtime. There are workarounds like implicit conversions, or maybe proxies.

Probably the "cleanest" way would be to make Increment a wrapper class delegating to an underlying Iterator. Depending on your use case there might be other solutions.

I feel that there has got to be an implicit conversion that will solve the trick. However, the solution continues to elude me. – wheaties Aug 15 '10 at 22:24.

A mixin inheritance happens at compile time, when it can be type-checked statically, and it is always targeted at another class, trait, etc. Here you try to tack a trait on an existing object "on the fly" at runtime. There are workarounds like implicit conversions, or maybe proxies. Probably the "cleanest" way would be to make Increment a wrapper class delegating to an underlying Iterator.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions