Search Results

Search found 972 results on 39 pages for 'scala'.

Page 24/39 | < Previous Page | 20 21 22 23 24 25 26 27 28 29 30 31  | Next Page >

  • Where can I download an SBT 0.13 snapshot package?

    - by Ivan
    Being stuck with a scala 2.9 compiler bug I've decided to try moving to Scala 2.10 RC. As a part of the switch I was trying to install SBT 0.13 snapshot. The official web page lists a broken link: http://scalasbt.artifactoryonline.com/scalasbt/sbt-native-packages/org/scala-sbt/sbt//0.13.0-SNAPSHOT/sbt.tgz There is nothing about 0.13 in the directory, the link gives Error 404. Any ideas about where to get the file?

    Read the article

  • How can I get a Node adjacent to a unique Node using Scala?

    - by pr1001
    I'm trying to parse an Apple plist file and I need to get an array Node within it. Unfortunately its only unique identifier is sibling Node right before it, <key>ProvisionedDevices</key>. Right now my best thoughts are to use Java's XPATH querying or Node.indexOf. Here is an example: <plist version="1.0"> <dict> <key>ApplicationIdentifierPrefix</key> <array> <string>RP8CBF4MRE</string> </array> <key>CreationDate</key> <date>2010-05-10T11:44:35Z</date> <key>DeveloperCertificates</key> <array> ... <key>ProvisionedDevices</key> <array> ... // I need the Nodes here </array> </dict> </plist> Thanks!

    Read the article

  • Which is the fastest idiomatic way to add all vectors (in the math sense) inside a Scala list?

    - by davips
    I have two solutions, but one doesn't compile and the other, I think, could be better: object Foo extends App { val vectors = List(List(1,2,3), List(2,2,3), List(1,2,2)) //just a stupid example //transposing println("vectors = " + vectors.transpose.map (_.sum)) //it prints vectors = List(4, 6, 8) //folding vectors.reduce { case (a, b) => (a zip b) map { case (x, y) => x + y } } //compiler says: missing parameter type for exp. function; arg. types must be fully known }

    Read the article

  • Why does `Array(0,1,2) == Array(0,1,2)` not return the expected result?

    - by soc
    As far as I understand, Scala's == defines the natural equality of two objects. I expected that Array(0,1,2) == Array(0,1,2) compares the natural equality e. g. checks if all elements of the array return true when compared with the corresponding elements of the other array. People told me that Scala's Array is just a Java [] which only compares identity. But Scala's String is also just a Java String but Scala overrides equals to compare natural equality. I wonder why Array's equals method was not overridden, too. Thank you for your thoughts!

    Read the article

  • Why people define class, trait, object inside another object in Scala?

    - by Zwcat
    Ok, I'll explain why I ask this question. I begin to read Lift 2.2 source code these days. In Lift, I found that, define inner class and inner trait are very heavily used. object Menu has 2 inner traits and 4 inner classes. object Loc has 18 inner classes, 5 inner traits, 7 inner objects. There're tons of codes write like this. I wanna to know why the author write it like this. Is it because it's the author's personal taste or a powerful use of language feature?

    Read the article

  • How do I declare a constructor for an 'object' class type in Scala? I.e., a one time operation for the singleton.

    - by Zack
    I know that objects are treated pretty much like singletons in scala. However, I have been unable to find an elegant way to specify default behavior on initial instantiation. I can accomplish this by just putting code into the body of the object declaration but this seems overly hacky. Using an apply doesn't really work because it can be called multiple times and doesn't really make sense for this use case. Any ideas on how to do this?

    Read the article

  • Is there a way to use scala with html5?

    - by Maik Klein
    I want to create a very simple 2d multiplayer browsergame in html5. Something like Scalatron I mainly want to do this to improve my scala skills, the problem is I would have to code the clientside code in javascript and the serverside code in scala. This would result in duplicated code. Another option would be to ignore the html5 part and write it in opengl. But I would still prefer to have a html5 game. I could do this is in javascript, but then it would destroy the whole purpose of learning scala. Is there a way to use scala with html5? Or what would you recommend me to do?

    Read the article

  • Better way for calculating project euler's 2nd problem Fibonacci sequence)

    - by firephil
    object Problem_2 extends App { def fibLoop():Long = { var x = 1L var y = 2L var sum = 0L var swap = 0L while(x < 4000000) { if(x % 2 ==0) sum +=x swap = x x = y y = swap + x } sum } def fib:Int = { lazy val fs: Stream[Int] = 0 #:: 1 #:: fs.zip(fs.tail).map(p => p._1 + p._2) fs.view.takeWhile(_ <= 4000000).filter(_ % 2 == 0).sum } val t1 = System.nanoTime() val res = fibLoop val t2 = (System.nanoTime() - t1 )/1000 println(s"The result is: $res time taken $t2 ms ") } Is there a better functional way for calculating the fibonaci sequence and taking the sum of the the even values below 4million ? (projecteuler.net - problem 2) The imperative method is 1000x faster ?

    Read the article

  • Why do case class companion objects extend FunctionN?

    - by retronym
    When you create a case class, the compiler creates a corresponding companion object with a few of the case class goodies: an apply factory method matching the primary constructor, equals, hashCode, and copy. Somewhat oddly, this generated object extends FunctionN. scala> case class A(a: Int) defined class A scala> A: (Int => A) res0: (Int) => A = <function1> This is only the case if: There is no manually defined companion object There is exactly one parameter list There are no type arguments The case class isn't abstract. Seems like this was added about two years ago. The latest incarnation is here. Does anyone use this, or know why it was added? It increases the size of the generated bytecode a little with static forwarder methods, and shows up in the #toString() method of the companion objects: scala> case class A() defined class A scala> A.toString res12: java.lang.String = <function0>

    Read the article

  • Case class copy() method abstraction.

    - by Joa Ebert
    I would like to know if it is possible to abstract the copy method of case classes. Basically I have something like sealed trait Op and then something like case class Push(value: Int) extends Op and case class Pop() extends Op. The first problem: A case class without arguments/members does not define a copy method. You can try this in the REPL. scala> case class Foo() defined class Foo scala> Foo().copy() <console>:8: error: value copy is not a member of Foo Foo().copy() ^ scala> case class Foo(x: Int) defined class Foo scala> Foo(0).copy() res1: Foo = Foo(0) Is there a reason why the compiler makes this exception? I think it is rather unituitive and I would expect every case class to define a copy method. The second problem: I have a method def ops: List[Op] and I would like to copy all ops like ops map { _.copy() }. How would I define the copy method in the Op trait? I get a "too many arguments" error if I say def copy(): this.type. However, since all copy() methods have only optional arguments: why is this incorrect? And, how do I do that correct? By making another method named def clone(): this.type and write everywhere def clone() = copy() for all the case classes? I hope not.

    Read the article

  • Groovy as a substitute for Java when using BigDecimal?

    - by geejay
    I have just completed an evaluation of Java, Groovy and Scala. The factors I considered were: readability, precision The factors I would like to know: performance, ease of integration I needed a BigDecimal level of precision. Here are my results: Java void someOp() { BigDecimal del_theta_1 = toDec(6); BigDecimal del_theta_2 = toDec(2); BigDecimal del_theta_m = toDec(0); del_theta_m = abs(del_theta_1.subtract(del_theta_2)) .divide(log(del_theta_1.divide(del_theta_2))); } Groovy void someOp() { def del_theta_1 = 6.0 def del_theta_2 = 2.0 def del_theta_m = 0.0 del_theta_m = Math.abs(del_theta_1 - del_theta_2) / Math.log(del_theta_1 / del_theta_2); } Scala def other(){ var del_theta_1 = toDec(6); var del_theta_2 = toDec(2); var del_theta_m = toDec(0); del_theta_m = ( abs(del_theta_1 - del_theta_2) / log(del_theta_1 / del_theta_2) ) } Note that in Java and Scala I used static imports. Java: Pros: it is Java Cons: no operator overloading (lots o methods), barely readable/codeable Groovy: Pros: default BigDecimal means no visible typing, least surprising BigDecimal support for all operations (division included) Cons: another language to learn Scala: Pros: has operator overloading for BigDecimal Cons: some surprising behaviour with division (fixed with Decimal128), another language to learn

    Read the article

  • Functional Programming - Lots of emphasis on recursion, why?

    - by peakit
    I am getting introduced to Functional Programming [FP] (using Scala). One thing that is coming out from my initial learnings is that FPs rely heavily on recursion. And also it seems like, in pure FPs the only way to do iterative stuff is by writing recursive functions. And because of the heavy usage of recursion seems the next thing that FPs had to worry about were StackoverflowExceptions typically due to long winding recursive calls. This was tackled by introducing some optimizations (tail recursion related optimizations in maintenance of stackframes and @tailrec annotation from Scala v2.8 onwards) Can someone please enlighten me why recursion is so important to functional programming paradigm? Is there something in the specifications of functional programming languages which gets "violated" if we do stuff iteratively? If yes, then I am keen to know that as well. PS: Note that I am newbie to functional programming so feel free to point me to existing resources if they explain/answer my question. Also I do understand that Scala in particular provides support for doing iterative stuff as well.

    Read the article

  • Default type-parametrized function literal class parameter

    - by doom2.wad
    Is this an intended behavior or is it a bug? Consider the following trait (be it a class, doesn't matter): trait P[T] { class Inner(val f: T => Unit = _ => println("nope")) } This is what I would have expected: scala> val p = new P[Int] { | val inner = new Inner | } p: java.lang.Object with P[Int]{def inner: this.Inner} = $anon$1@12192a9 scala> p.inner.f(5) nope But this? scala> val p = new P[Int] { | val inner = new Inner() { | println("some primary constructor code in here") | } | } <console>:6: error: type mismatch; found : (T) => Unit required: (Int) => Unit val inner = new Inner() { ^

    Read the article

  • how to translate Haskell into Scalaz?

    - by TOB
    One of my high school students and I are going to try to do a port of Haskell's Parsec parser combinator library into Scala. (It has the advantage over Scala's built-in parsing library that you can pass state around fairly easily because all the parsers are monads.) The first hitch I've come across is trying to figure out how Functor works in scalaz. Can someone explain how to convert this Haskell code: data Reply s u a = Ok a !(State s u) ParseError | Error ParseError instance Functor (Reply s u) where fmap f (Ok x s e) = Ok (f x) s e fmap _ (Error e) = Error e -- XXX into Scala (using Scalaz, I assume). I got as far as sealed abstract class Reply[S, U, A] case class Ok[S, U, A](a: A, state: State[S, U], error: ParseError) extends Reply[S, U, A] case class Error[S, U, A](error: ParseError) extends Reply[S, U, A] and know that I should make Reply extend the scalaz.Functor trait, but I can't figure out how to do that. (Mostly I'm having trouble figuring out what the F[_] parameter does.) Any help appreciated! Thanks, Todd

    Read the article

  • What is the most efficient functional version of the following imperative code?

    - by justin.r.s.
    I'm learning Scala and I want to know the best way of expressing this imperative pattern using Scala's functional programming capabilities. def f(l: List[Int]): Boolean = { for (e <- l) { if (test(e)) return true } } return false } The best I can come up with is along the lines of: l map { e => test(e) } contains true But this is less efficient since it calls test() on each element, whereas the imperative version stops on the first element that satisfies test(). Is there a more idiomatic functional programming technique I can use to the same effect? The imperative version seems awkward in Scala.

    Read the article

  • Tied up with injection implemented with setter functions

    - by puudeli
    Hi, I'm trying to use Scala as part of an existing Java application and now I run into an issue with dependencies injected with a setter method (no DI frameworks in this part of code). How is this handled in a Scala way? In Scala both val and var require to be initialized when declared but I can't do that, since the Java setters inject objects that implement a certain interface and interfaces are abstract and can not be instantiated. class ScalaLogic { var service // How to initialize? def setService (srv: OutputService) = { service = srv } Is there a way to initialize the var service so that I can later assign a dependency into it? It should be lexically scoped to be visible in the whole class.

    Read the article

  • Play Framework Form "fold" method naming rationale

    - by oym
    Play Framework's (2.x) Form class has a method called fold who's usage is indicated as: anyForm.bindFromRequest().fold( f => redisplayForm(f), t => handleValidFormSubmission(t) ) Essentially, the first function parameter is what gets executed on binding failure, and the 2nd on binding success. To me it seems similar to the 'success' and 'error' callbacks of jquery's ajax function. My question is why did the Play developers call the method "fold"? As a disclaimer I am new to Scala, but I am failing to see the connection between this and the functional Scala fold operation. The only similarity is that it is a higher order function; but I don't see any combining that is taking place, nor does it delegate internally in its implementation to any of the Scala fold functions.

    Read the article

  • What is "Call By Name"?

    - by forellana
    Hi to everyone! I'm working in a homework, and the professor asked me to implement the evaluation strategy called "call by name" in scheme in a certain language that we developed and he gave us an example at http://www.scala-lang.org/node/138 in the scala language, but i don't understand in what consists the call by name evaluation strategy? what differences it has with call by need? thanks, greetings

    Read the article

  • Resources for learning Monads, Functors, Monoids, Arrows etc

    - by Dony Borris
    Can you people please suggest some good books / weblinks from where I can get to learn about above mentioned concepts? (Please note that I am a Java programmer and have NO prior experience with functional programming. I have been studying Scala since last one month and would appreciate the resources that try to teach the above mentioned concepts with Scala. (or even Java, if posible))

    Read the article

  • How Do I Convert Pipe Delimited to Comma Delimited with Escaping

    - by Russ Bradberry
    Hi, I am fairly new to scala and I have the need to convert a string that is pipe delimited to one that is comma delimited, with the values wrapped in quotes and any quotes escaped by "\" in c# i would probably do this like this string st = "\"" + oldStr.Replace("\"", "\\\\\"").Replace("|", "\",\"") + "\"" I haven't validated that actually works but that is the basic idea behind what I am trying to do. Is there a way to do this easily in scala?

    Read the article

< Previous Page | 20 21 22 23 24 25 26 27 28 29 30 31  | Next Page >