Eric Willigers | 1 Mar 02:25 2008
Picon

Re: Iterable.partition return type

J Robert Ray wrote:
> I found Iterable.partition and it is the kind of operation I find myself
> needing on occasion, but I am frustrated by its return type and the choice
> to return Iterables.
> 
> In one case, I want to split an array and send one of the pieces to a
> function that takes a RandomAccessSeq.
> 
> Partition uses ArrayBuffers internally to construct the two outputs.  But
> because I don't want to make assumptions about the implementation, I don't
> want to use asInstanceOf in my code.
> 
> My choices to convert an Iterable into an Array are less than ideal.  I
> already have something that I could pass to my function if it weren't
> masquerading as an Iterable.
> 
> foo.toList.toArray
> foo.copyToArray(bar, 0)
> Others?
> 
> What I ended up doing was to write my own partition utility that returns
> ArrayBuffers.
> 
> There are other functions in the Iterable class that return a narrower type,
> e.g., take: Collection, so would it be wrong for partition to be declared to
> return a type closer to ArrayBuffer?

RandomAccessSeq[A] (and hence Array) could override partition to return
(RandomAccessSeq[A], RandomAccessSeq[A])

(Continue reading)

behlma | 1 Mar 13:41 2008

Re: Class, classOf etc.


Hi guys,
thanks for the help. But now the compiler spits out a new error message:

actions.put("dummyAction", classOf[DummyAction])  gives me ->

[WARNING]
D:\Code\scalatest\src\main\scala\net\scalatest\request\Application.scala:19:
error: type mismatch;
[WARNING]  found   : java.lang.Class[net.scalatest.actions.DummyAction]
[WARNING]  required: java.lang.Class[T forSome { type T <:
net.scalatest.actions.TAction }]

Any ideas?

Blair Zajac wrote:
> 
> behlma wrote:
>> Hi guys, 
>> I'm quite new to Scala and was just wondering how/if the following works?
>> 
>> Suppose I want to add classnames to a HashMap, but only classes that
>> extend
>> a certain trait.
>> 
>> For example:
>> 
>> val actions = new HashMap[String, Class[TAction]]?
> 
> val actions = new HashMap[String, Class[T forSome { type T <: TAction }]]
(Continue reading)

Jan Kriesten | 1 Mar 14:35 2008
Picon

Accessing methods/vals from companion object


Hi,

is there a shortcut to access methods and vals from a companion object _without_ 
prefixing it with the class name or explicitly importing it.

It's a bit of an annoyence having a companion object within the same file and do 
an import to access fields/values on it.

Best regards, --- Jan.

David MacIver | 1 Mar 15:34 2008
Picon

Re: Class, classOf etc.

You want:

 val actions = new HashMap[String, Class[T] forSome { type T <: TAction }]

Not

 val actions = new HashMap[String, Class[T forSome { type T <: TAction }]]

On Sat, Mar 1, 2008 at 12:41 PM, behlma <behlma@...> wrote:
>
>  Hi guys,
>  thanks for the help. But now the compiler spits out a new error message:
>
>  actions.put("dummyAction", classOf[DummyAction])  gives me ->
>
>  [WARNING]
>  D:\Code\scalatest\src\main\scala\net\scalatest\request\Application.scala:19:
>  error: type mismatch;
>  [WARNING]  found   : java.lang.Class[net.scalatest.actions.DummyAction]
>  [WARNING]  required: java.lang.Class[T forSome { type T <:
>  net.scalatest.actions.TAction }]
>
>  Any ideas?
>
>
>
>
>
>  Blair Zajac wrote:
>  >
(Continue reading)

behlma | 1 Mar 16:14 2008

Re: Class, classOf etc.


Thanks a lot, that works!

David MacIver wrote:
> 
> You want:
> 
>  val actions = new HashMap[String, Class[T] forSome { type T <: TAction }]
> 
> Not
> 
>  val actions = new HashMap[String, Class[T forSome { type T <: TAction }]]
> 
> 
> On Sat, Mar 1, 2008 at 12:41 PM, behlma <behlma@...> wrote:
>>
>>  Hi guys,
>>  thanks for the help. But now the compiler spits out a new error message:
>>
>>  actions.put("dummyAction", classOf[DummyAction])  gives me ->
>>
>>  [WARNING]
>> 
>> D:\Code\scalatest\src\main\scala\net\scalatest\request\Application.scala:19:
>>  error: type mismatch;
>>  [WARNING]  found   : java.lang.Class[net.scalatest.actions.DummyAction]
>>  [WARNING]  required: java.lang.Class[T forSome { type T <:
>>  net.scalatest.actions.TAction }]
>>
>>  Any ideas?
(Continue reading)

David MacIver | 1 Mar 16:18 2008
Picon

Re: Class, classOf etc.

No problem.

Also, it seems like *everyone* has been having this problem recently,
so I wrote up a small introduction. See
http://unenterprise.blogspot.com/2008/03/existential-types-in-scala.html

Hope it helps.

David

On Sat, Mar 1, 2008 at 3:14 PM, behlma <behlma@...> wrote:
>
>  Thanks a lot, that works!
>
>
>
>
>
>  David MacIver wrote:
>  >
>  > You want:
>  >
>  >  val actions = new HashMap[String, Class[T] forSome { type T <: TAction }]
>  >
>  > Not
>  >
>  >  val actions = new HashMap[String, Class[T forSome { type T <: TAction }]]
>  >
>  >
>  > On Sat, Mar 1, 2008 at 12:41 PM, behlma <behlma@...> wrote:
(Continue reading)

Zemian Deng | 1 Mar 20:48 2008
Picon

import pattern selection of classes from package

Hi,
Is there way I can import all classes that end with "Wrapper" in scala.collection.jcl package into my program?

Thks
-Zemian

shameed | 1 Mar 22:33 2008
Picon

Another super class constructor query


When I run the code

class Bar(o: Object){
	System.out.println(o);  
}
class Foo extends Bar{

}

  var f = new Foo(); <--- returns () ... a Unit

My question is why is it letting me extend from a class which only has a
single, one parameter, constructor without passing anything to the parent?
and how does it under the hood pass in a Unit.

Also if I need to extend from the java class PropertyChangeSupport which
only has a single constructor 
PropertyChangeSupport(Object sourceBean) and I want to pass it a "this" from
the child class how can I do that since I am not allowed to call super?

I cannot do class BP extends PropertyChangeSupport(this) <-- obviously
complains about this

Thanks.

~Sadiya

--

-- 
View this message in context: http://www.nabble.com/Another-super-class-constructor-query-tp15781271p15781271.html
Sent from the Scala - User mailing list archive at Nabble.com.

Chris Hansen | 1 Mar 22:25 2008
Picon

Re: Accessing methods/vals from companion object

I'm pretty sure there is not. Even though they are in the same file, they are not in the same scope.

-Chris

On Sat, Mar 1, 2008 at 6:35 AM, Jan Kriesten <jan.kriesten-JLLwi6Ap6O+oYr4blSSd5g@public.gmane.org> wrote:

Hi,

is there a shortcut to access methods and vals from a companion object _without_
prefixing it with the class name or explicitly importing it.

It's a bit of an annoyence having a companion object within the same file and do
an import to access fields/values on it.

Best regards, --- Jan.



Arco Oost | 1 Mar 23:28 2008
Picon

Re: Accessing methods/vals from companion object

Jan,

You can import the companion object into the class, like so:

---------------------------------
package test

object Companion {
  def hello = println("Hello")
}

class Companion {
  import Companion._
  hello
}
---------------------------------

Regards,
  Arco

Jan Kriesten wrote:
>
> Hi,
>
> is there a shortcut to access methods and vals from a companion object 
> _without_ prefixing it with the class name or explicitly importing it.
>
> It's a bit of an annoyence having a companion object within the same 
> file and do an import to access fields/values on it.
>
> Best regards, --- Jan.
>
>
>


Gmane