The Artima Developer Community
Sponsored Link

Weblogs Forum
Pimp my Library

32 replies on 3 pages. Most recent reply: Aug 17, 2012 6:35 AM by Ugo Matrangolo

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 32 replies on 3 pages [ « | 1 2 3 ]
Luke Hutchison

Posts: 1
Nickname: lukehutch
Registered: May, 2010

Re: Pimp my Library Posted: May 13, 2010 1:53 AM
Reply to this message Reply
Advertisement
In the following example you reference the parameter x in the body of the conversion:

implicit def array2string[T](x: Array[T]) = x.toString

However in the following example you don't reference xs in the new statement:

implicit def enrichArray[T](xs: Array[T]) = new RichArray[T]

Shouldn't that be new RichArray[T](xs), or is (xs) somehow being curried?

Daniel Sobral

Posts: 78
Nickname: 57409
Registered: Aug, 2008

Re: Pimp my Library Posted: Aug 4, 2011 11:03 AM
Reply to this message Reply
Contrary to what is said in the article, Scala's Array doesn't have a usable toString anymore.

Ugo Matrangolo

Posts: 1
Nickname: 66493
Registered: May, 2009

Re: Pimp my Library Posted: Aug 17, 2012 6:35 AM
Reply to this message Reply
I was not able to use the code from the post.

Actually the RichArray class should be :

class RichArray[T](value: Array[T]){
def append(other: Array[T])(implicit m: Manifest[T]) : Array[T] = {
val result = new Array[T](value.length + other.length)
Array.copy(value, 0, result, 0, value.length)
Array.copy(other, 0, result, value.length, other.length)
result
}
}

and ..

implicit def enrichArray[T](xs: Array[T]) = new RichArray[T](xs)

Cheers

Flat View: This topic has 32 replies on 3 pages [ « | 1  2  3 ]
Topic: Gentle Introduction to Scala: The Seminar Previous Topic   Next Topic Topic: Software Documentation Is Like Weather and Pornography


Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2014 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us