Search Results

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

Page 28/39 | < Previous Page | 24 25 26 27 28 29 30 31 32 33 34 35  | Next Page >

  • Compilation issues using scalaz's MA methods on Set but not List

    - by oxbow_lakes
    The following compiles just fine using scala Beta1 and scalaz snapshot 5.0: val p1: Int => Boolean = (i : Int) => i > 4 val s: List[Int] = List(1, 2, 3) val b1 = s ? p1 And yet this does not: val s: Set[Int] = Set(1, 2, 3) val b1 = s ? p1 I get the following error: Found: Int = Boolean Required: Boolean = Boolean The signature of the ? method is: def ?(p: A => Boolean)(implicit r: FoldRight[M]): Boolean = any(p) And there should be an implicit SetFoldRight in scope. It is exactly the same for the methods: ?, ? and ?: - what is going on?

    Read the article

  • Simple cross platform GUI app

    - by Joe Cannatti
    I would like to know if there is any way that I could build a very simple GUI app (it doesn't even have to look good) that will run on a fresh install of Windows Vista and OS X with no other installations needed by the user. I would perfer not to use Java (just out of personal programming preference). I will use it though, if it is the only way. Specically, I am wondering if I can write a swing app with Scala or Groovy and run in on windows without them having to install anything. Sorry if this is a silly question, I am a Obj-C developer by trade.

    Read the article

  • Classes missing if application runs for a long time

    - by Rogach
    I have a funny problem - if my application runs for a long time ( 20h), then sometimes I get NoClassDefFound error - seems like JVM decided that the class is not going to be used anyway and GCd it. To be a bit more specific, here's an example case: object ErrorHandler extends PartialFunction[Throwable,Unit] { def isDefinedAt(t: Throwable) = true def apply(e: Throwable) =e match { // ... handle errors } } // somewhere else in the code... try { // ... long running code, can take more than 20 hours to complete } catch (ErrorHandler) And I get the following exception: Exception in thread "main" java.lang.NoClassDefFoundError: org/rogach/avalanche/ErrorHandler$ If that try/catch block runs for smaller amounts of time, everything works as expected. If anyone is interested, here is the codebase in question: Avalanche I need to note that I saw this and similar problems only on Cent OS 5 machines, using JRE 6u26 and Scala 2.9.1 / 2.9.2. What could be the cause of this problem?

    Read the article

  • The cost of nested methods

    - by Palimondo
    In Scala one might define methods inside other methods. This limits their scope of use to inside of definition block. I use them to improve readability of code that uses several higher-order functions. In contrast to anonymous function literals, this allows me to give them meaningful names before passing them on. For example: class AggregatedPerson extends HashSet[PersonRecord] { def mostFrequentName: String = { type NameCount = (String, Int) def moreFirst(a: NameCount, b: NameCount) = a._2 > b._2 def countOccurrences(nameGroup: (String, List[PersonRecord])) = (nameGroup._1, nameGroup._2.size) iterator.toList.groupBy(_.fullName). map(countOccurrences).iterator.toList. sortWith(moreFirst).head._1 } } Is there any runtime cost because of the nested method definition I should be aware of? Does the answer differ for closures?

    Read the article

  • Using type aliases to Java enums

    - by oxbow_lakes
    I would like to achieve something similar to how scala defines Map as both a predefined type and object. In Predef: type Map[A, +B] = collection.immutable.Map[A, B] val Map = collection.immutable.Map //object Map However, I'd like to do this using Java enums (from a shared library). So for example, I'd have some global alias: type Country = my.bespoke.enum.Country val Country = my.bespok.enum.Country //compile error: "object Country is not a value" The reason for this is that I'd like to be able to use code like: if (city.getCountry == Country.UNITED_KINGDOM) //or... if (city.getCountry == UNITED_KINGDOM) Howver, this not possible whilst importing my type alias at the same time. Note: this code would work just fine if I had not declared a predefined type and imported it! Is there some syntax I can use here to achieve this?

    Read the article

  • Scala programming language for beginners, is it a legend?

    - by ali
    Hi every one, I am Ali from Saudi Arabia. undoubtedly, Scala is one of the best programming language for any programmer to learn, but there is "good" problems that is faced especially by beginners, and what seems frustrating that these problems won't solve soon, so as a beginner and on behalf of beginners let me raise these "objective" questions: 1- why scala has no effective and stable development platform, in fact, it suffers many problems with Eclipse, Netbeat, and Intellij. 2- although I have looked for a clear,easy, and understandable explanation of how to get started with Scala, but fortunately, there was no article or guide that deserves to spend the time I have spent to read it. nobody could tell you clear steps that fit you as a beginner who wants to start his"HELLO WORLD" with Scala, while all other languages have its "HELLO WORLD" guides and books. thank you for your time, be sure that you read notes below. 1- I have no experience in programming language before. 2- don't tell me "not to begin with scala", simply, because I will do. 3- OS is windows vista home premium. 4- I hate excuses, such as Scala is new language......etc

    Read the article

  • Functional languages targeting the LLVM

    - by Matthew
    Are there any languages that target the LLVM that: Are statically typed Use type inference Are functional (i.e. lambda expressions, closures, list primitives, list comprehensions, etc.) Have first class object-oriented features (inheritance, polymorphism, mixins, etc.) Have a sophisticated type system (generics, covariance and contravariance, etc.) Scala is all of these, but only targets the JVM. F# (and to some extent C#) is most if not all of these, but only targets .NET. What similar language targets the LLVM?

    Read the article

  • Avoiding NPE in trait initialization without using lazy vals

    - by 0__
    This is probably covered by the blog entry by Jesse Eichar—still I can't figure out how to correct the following without residing to lazy vals so that the NPE is fixed: Given trait FooLike { def foo: String } case class Foo( foo: String ) extends FooLike trait Sys { type D <: FooLike def bar: D } trait Confluent extends Sys { type D = Foo } trait Mixin extends Sys { val global = bar.foo } First attempt: class System1 extends Mixin with Confluent { val bar = Foo( "npe" ) } new System1 // boom!! Second attempt, changing mixin order class System2 extends Confluent with Mixin { val bar = Foo( "npe" ) } new System2 // boom!! Now I use both bar and global very heavily, and therefore I don't want to pay a lazy-val tax just because Scala (2.9.2) doesn't get the initialisation right. What to do?

    Read the article

  • Immutability of big objects

    - by Malax
    Hi StackOverflow! I have some big (more than 3 fields) Objects which can and should be immutable. Every time I run into that case i tend to create constructor abominations with long parameter lists. It doesn't feel right, is hard to use and readability suffers. It is even worse if the fields are some sort of collection type like lists. A simple addSibling(S s) would ease the object creation so much but renders the object mutable. What do you guys use in such cases? I'm on Scala and Java, but i think the problem is language agnostic as long as the language is object oriented. Solutions I can think of: "Constructor abominations with long parameter lists" The Builder Pattern Thanks for your input!

    Read the article

  • Workaround for abstract attributes in Java

    - by deamon
    In Scala I would write an abstract class with an abstract attribute path: abstract class Base { val path: String } class Sub extends Base { override val path = "/demo/" } Java doesn't know abstract attributes and I wonder what would be the best way to work around this limitation. My ideas: a) constructor parameter abstract class Base { protected String path; protected Base(String path) { this.path = path; } } class Sub extends Base { public Sub() { super("/demo/"); } } b) abstract method abstract class Base { // could be an interface too abstract String getPath(); } class Sub extends Base { public String getPath() { return "/demo/"; } } Which one do you like better? Other ideas? I tend to use the constructor since the path value should not be computed at runtime.

    Read the article

  • Optional attribute values in MappedField

    - by David Brooks
    I'm new to Scala and Lift, coming from a slightly odd background in PLT Scheme. I've done a quick search on this topic and found lots of questions but no answers. I'm probably looking in the wrong place. I've been working my way through tutorials on using Mapper to create database-backed objects, and I've hit a stumbling block: what types should be used to stored optional attribute values. For example, a simple ToDo object might comprise a title and an optional deadline (e.g. http://rememberthemilk.com). The former would be a MappedString, but the latter could not be a MappedDateTime since the type constraints on the field require, say, defaultValue to return a Date (rather than a Date or null/false/???). Is an underlying NULL handled by the MappedField subclasses? Or are there optional equivalents to things like MappedInt, MappedString, MappedDateTime that allow the value to be NULL in the database? Or am I approaching this in the wrong way?

    Read the article

  • How to get everything in the string, but a particular pattern

    - by José Leal
    Yet another regexp question: I have a string as the following, "This is a string, and I have a priority !1" So I want to build a regexp that extracts my priority, which is this number 1 preceded by the "!". To extract it is very easy, "!([1-4])". But now I want to extract the text, leaving it out! How can I do that? DETAIL: The !1 can be anywhere in the string, so this is also perfectly fine: "This is a string, !1 and I have a priority" Thanks! UPDATE: I'm using scala

    Read the article

  • Alternatives to java on android

    - by user84584
    Hello guys, I just got myself an android phone and I'm dying to start coding on it ! However I'm not a big java fan, although I can live with that, I would like to know if there're reasonable alternatives for the android virtual machine. I've done a medium sized project using clojure, however from the reviews I read, it's very slow when running on android. How about scala ? I read that some people did experiments with it in android, is it "fast enough" ? How big is the learning curve ? Cheers, Ze Maria

    Read the article

  • where do i put html files in my web-app folder for a lift project with maven?

    - by egervari
    I'm new to Lift framework for scala. For some reason, index.html resides in the web-app directory, and when I start up jetty, http://localhost:8080/ will point to that index.html file just fine. However, if I put a login.html file in the same folder as the index.html, and then go http://localhost:8080/login, Lift does not serve the file. Where do I need to put the files to get them register? I am a little lost because the behaviour only seems to work for index.html and nothing else. This is what happens when I view source in Chrome: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html> <body>The Requested URL /login was not found on this server</body> </html>

    Read the article

  • Passing arguments to anonymous inner classes

    - by synic
    I'm trying to make an API library for our web services, and I'm wondering if it's possible to do something like this: abstract class UserRequest(val userId: Int) { def success(message: String) def error(error: ApiError) } api.invokeRequest(new UserRequest(121) { override def success(message: String) = { // handle success } override def error(error: ApiError) = { // handle the error } } I'm talking about passing parameters to the anonymous inner class, and also overriding the two methods. I'm extremely new to Scala, and I realize my syntax might be completely wrong. I'm just trying to come up with a good design for this library before I start coding it. I'm willing to take suggestions for this, if I'm doing it the completely wrong way, or if there's a better way. The idea is that the API will take some sort of request object, use it to make a request in a thread via http, and when the response has been made, somehow signal back to the caller if the request was a success or an error. The request/error functions have to be executed on the main thread.

    Read the article

  • Should I use implicit conversions to enforce preconditions?

    - by Malvolio
    It occurs to me that I could use use implicit conversions to both announce and enforce preconditions. Consider this: object NonNegativeDouble { implicit def int2nnd(d : Double) : NonNegativeDouble = new NonNegativeDouble(d) implicit def nnd2int(d : NonNegativeDouble) : Double = d.v def sqrt(n : NonNegativeDouble) : NonNegativeDouble = scala.math.sqrt(n) } class NonNegativeDouble(val v : Double ) { if (v < 0) { throw new IllegalArgumentException("negative value") } } object Test { def t1 = { val d : Double = NonNegativeDouble.sqrt(3.0); printf("%f\n", d); val n : Double = NonNegativeDouble.sqrt(-3.0); } } Ignore for the moment the actual vacuity of the example: my point is, the subclass NonNegativeDouble expresses the notion that a function only takes a subset of the entire range of the class's values. First is this: A good idea, a bad idea, or an obvious idea everybody else already knows about Second, this would be most useful with basic types, like Int and String. Those classes are final, of course, so is there a good way to not only use the restricted type in functions (that's what the second implicit is for) but also delegate to all methods on the underlying value (short of hand-implementing every delegation)?

    Read the article

  • Constructor with non-instance variable assistant?

    - by Robert Fischer
    I have a number of classes that look like this: class Foo(val:BasicData) extends Bar(val) { val helper = new Helper(val) val derived1 = helper.getDerived1Value() val derived2 = helper.getDerived2Value() } ...except that I don't want to hold onto an instance of "helper" beyond the end of the constructor. In Java, I'd do something like this: public class Foo { final Derived derived1, derived2; public Foo(BasicData val) { Helper helper = new Helper(val); derived1 = helper.getDerived1Value(); derived2 = helper.getDerived2Value(); } } So how do I do something like that in Scala? I'm aware of creating a helper object of the same name of the class with an apply method: I was hoping for something slightly more succinct.

    Read the article

  • How can I get Syslogging to work on the JVM?

    - by Synesso
    I want to do syslogging from Java. There is a log4j appender, but it doesn't seem to work (for me anyway ... though Google results show many others with this issue still unresolved). I'm trying to debug the appender, so I've written the following script based upon RFC3164 It runs, but no logging appears in the syslog. // scala import java.io._ import java.net._ val ds = new DatagramSocket() val fullMsg = "<11>May 26 14:47:22 Hello World" val packet = new DatagramPacket(fullMsg.getBytes("UTF-8"), fullMsg.length, InetAddress.getLocalHost, 514) ds send packet ds.close I also tried using /bin/nc, but it doesn't work either. echo "<14>May 26 15:23:83 Hello world" > nc -u localhost 514 The Ubuntu command /usr/bin/logger does work, however. logger -p user.info hello world # logs: May 26 15:25:10 dsupport2 jem: hello world What could I be doing wrong?

    Read the article

  • error: polymorphic expression with default arguments

    - by 0__
    This following bugs me: trait Foo[ A ] class Bar[ A ]( set: Set[ Foo[ A ]] = Set.empty ) This yields <console>:8: error: polymorphic expression cannot be instantiated to expected type; found : [A]scala.collection.immutable.Set[A] required: Set[Foo[?]] class Bar[ A ]( set: Set[ Foo[ A ]] = Set.empty ) ^ It is quite annoying that I have to repeat the type parameter in Set.empty. Why does the type inference fail with this default argument? The following works: class Bar[ A ]( set: Set[ Foo[ A ]] = { Set.empty: Set[ Foo[ A ]]}) Please note that this has nothing to do with Set in particular: case class Hallo[ A ]() class Bar[ A ]( hallo: Hallo[ A ] = Hallo.apply ) // nope Strangely not only this works: class Bar[ A ]( hallo: Hallo[ A ] = Hallo.apply[ A ]) ...but also this: class Bar[ A ]( hallo: Hallo[ A ] = Hallo() ) // ???

    Read the article

  • Running a method after the constructor of any derived class

    - by Alexey Romanov
    Let's say I have a Java class abstract class Base { abstract void init(); ... } and I know every derived class will have to call init() after it's constructed. I could, of course, simply call it in the derived classes' constructors: class Derived1 extends Base { Derived1() { ... init(); } } class Derived2 extends Base { Derived2() { ... init(); } } but this breaks "don't repeat yourself" principle rather badly (and there are going to be many subclasses of Base). Of course, the init() call can't go into the Base() constructor, since it would be executed too early. Any ideas how to bypass this problem? I would be quite happy to see a Scala solution, too.

    Read the article

  • How to expose a constructor variable(sic!) as read-only?

    - by Malax
    Hi StackOverflow! I have this rather simple question about Scala. Given that i have to following class definition: class Foo(var bar: Int) The code which is able to construct an instance of Foo must be able to pass the initial value for bar. But if I define bar as var the User is also able to change its value at runtime which is not what I want. The User should only be able to read bar. bar itself is modified internally so a val is not an option. I think I might be getting an answer very soon as this question is so simple. :-) Cheers, Malax

    Read the article

  • Adding Apache common dependency to Play Framework 2.0

    - by Mooh
    i want to import org.apache.commons.io but i'm getting this error: [info] Compiling 1 Java source to /home/ghost/Bureau/app/play-2.0.1/waf/target/scala-2.9.1/classes... [error] /home/ghost/Bureau/app/play-2.0.1/waf/app/controllers/Application.java:9: error: package org.apache.commons.io does not exist [error] import org.apache.commons.io.*; [error] ^ [error] /home/ghost/Bureau/app/play-2.0.1/waf/app/controllers/Application.java:41: error: cannot find symbol [error] FileUtils.copyFile(file, destinationFile); [error] ^ [error] symbol: variable FileUtils [error] location: class Application [error] 2 errors [error] {file:/home/ghost/Bureau/app/play-2.0.1/waf/}waf/compile:compile: javac returned nonzero exit code [error] application - Play can't find package org.apache.commons.io . How i can i add it as a dependency ?

    Read the article

  • Possible to not use ID field but another column name? in Lift

    - by bstevens90
    I am connected to a oracle database from a scala/lift webapp. I have been able to successfully pull information from the database as I wished but am having one issue. For each table I want to access I am required to add an ID field so that the app will work with the trait IdPK. What mapper class or trait can I use to override this? I have been trying to find one but been unable to locate it. Figured people have not always had an ID field on every table they make that is just called ID... class DN_REC extends LongKeyedMapper[DN_REC] with IdPK { def getSingleton = DN_REC object dn_rec_id extends MappedInt(this){ } This is what I am talking about. I would like to use the dn_rec_id as my primary key as it is on the table. Thanks

    Read the article

  • GAE JCache NumberFormatException, will I need to write Java to avoid?

    - by Jasper
    This code below produces a NumberFormatException in this line: val cache = cf.createCache(Collections.emptyMap()) Do you see any errors? Will I need to write a Java version to avoid this, or is there a Scala way? ... import java.util.Collections import net.sf.jsr107cache._ object QueryGenerator extends ServerResource { private val log = Logger.getLogger(classOf[QueryGenerator].getName) } class QueryGenerator extends ServerResource { def getCounter(cache:Cache):long = { if (cache.containsKey("counter")) { cache.get("counter").asInstanceOf[long] } else { 0l } } @Get("html") def getHtml(): Representation = { val cf = CacheManager.getInstance().getCacheFactory() val cache = cf.createCache(Collections.emptyMap()) val counter = getCounter(cache) cache.put("counter", counter + 1) val q = QueueFactory.getQueue("query-generator") q.add(TaskOptions.Builder.url("/tasks/query-generator").method(Method.GET).countdownMillis(1000L)) QueryGenerator.log.warning(counter.toString) new StringRepresentation("QueryGenerator started!", MediaType.TEXT_HTML) } } Thanks!

    Read the article

  • Setting cookie in LiftFilter

    - by Gero
    Hi, How do I set a cookie in a LiftFilter.doFilter method? I tried to set the cookie as follows (stripped some code): class AuthenticationFilter extends LiftFilter { override def doFilter(request: ServletRequest, response: ServletResponse , chain: FilterChain) { val cookie = new HTTPCookie("SomeCookie", Full("" + System.nanoTime), Empty, Full("/authentication"), Full(60 * 60 * 24 * 14), Empty, Empty) cookie.setPath("/somePath") S.addCookie(cookie) val httpResp = response.asInstanceOf[HttpServletResponse] httpResp.sendRedirect("/some/page.html") } } However, when I check the browsers cookie, no cookie is set (apart from JSESSIONID), and I know the doFilter method is being executed because of logging messages and the fact that the browser is redirected to /some/page.html. I'm using Scala 2.8, Lift 2.1-SNAPSHOT and the app is running is GAE (1.3.6, only tested on dev_appserver so far). Any ideas? Thanks, Gero

    Read the article

< Previous Page | 24 25 26 27 28 29 30 31 32 33 34 35  | Next Page >