background preloader

Scala

Facebook Twitter

Liftweb setup in 10 minutes - IDE and project configuration. Scala is one of the coolest programming languages out there and Lift is a revolutionary web framework that really leverages many scala features. But it can be daunting at the beginning, even just getting your workspace setup. In this article I will go through the basic setup of your IDE, it really takes a few minutes! Even though I've always been an Eclipse person I'm using IDEA IntelliJ with Scala cause I think is way superior. Ok let's begin.

You will need IntelliJ 10.5.1, Maven or SBT. First step is to create the project and for that we will use lift maven archetype. 1.mvn archetype:generate -DarchetypeGroupId=net.liftweb 2. 3. 4. 6. You can also create a JPA based project running the same command with 1.archetypeArtifactId=lift-archetype-jpa-basic_2.8.1 You already have a full liftweb project! Next open IntelliJ and install the scala plugin. Now go to the plugins, pick scala right click "Download and Install" and once done restart the IDE. /build.sbt 01.name := "liftplay" 20. 22. 24. 26. Learnings from Actor Development. I spent a fair amount of time developing actor-based systems recently, specifically with the Scala Actor library.

Regardless of whether you are implementing actors with the Scala library, Akka, Lift or Scalaz, some basic gotchas can present themselves until you get a feel for what you're doing. Here are some of them that I've learned the hard way. Never Refer Directly to Other ActorsActors are fragile and can die easily. While you typically create a supervisor with a strategy for how to recreate that actor, any other class with a direct reference to that actor that died now has an invalid reference.

If you absolutely must have actors with references to others that do not have a supervisory relationship, use a proxy reference instead - if the actor behind the proxy dies, you only have to replace it in the proxy, not in every actor with that reference. Write Business Logic in External Idempotent FunctionsTesting actors is difficult, particularly those with side effects. Java Without Semicolons: An Introduction to Scala - Part 1: Iteration.

This series of posts was inspired by a suggestion from Martin Oedersky at Scala Days 2011 as well as something I have heard Dick Wall say on several occasions. To paraphrase Dick, you can get started with Scala by converting Java code to Scala with few changes beyond getting rid of the semicolons. It may not take advantage of many of Scala's more powerful features, but it's a great way to get started and an excellent jumping off point to learning Scala's richer language features. Scala is a deep and flexible language that allows an enormous degree of freedom to library developers and advanced users, but those features can be daunting to new developers trying to take them all in. So, what areas should a Java programmer getting started with Scala start with? This blog series will cover Scala features that Java programmers should be able to put to immediate use.

Setup Iteration As a longtime Java developer, I was immediately drawn to Scala's alternatives to for-loop iteration. Scala-integrated-query - Scala Intergrated Query - a database query dsl for scala. Update: We are currently working on project Slick, integrating ideas from Scala Integrated Query, Scala Query and additional techniques for compile time processing and optimizations. We made an initial release in summer 2012. Scala Integrated Query is a prototype developed at LAMP, EPFL. It compiles a subset of Scala into SQL and executes it in the DBMS. Queries can result in single values or arbitrarily nested lists and tuples, which can require more than one SQL query. Compared to using SQL directly, using Scala Integrated Query can lead to more accurate code and makes it easier to achieve good performance for complex queries.

It features greater expressiveness, type safety, familiar syntax and easy composability. Complex queries are efficiently mapped to SQL and automatically optimized. SIQ Thesis (PDF) Talks about SIQ Stanford University, Scala Days 2011, June 2011 overview, motivation, use case Slides (+extras) | Video | Announcement EPFL Lausanne, Switzerland, August 2011 Slides Slides. Monadic Continuations in Scala | Earl Douglas.

Of monads and games. Motivation This work began with a desire to construct a simple and easily understandable example to illustrate separating out the monad API from the underlying structure that supports it. In Haskell this division of labor is well understood. The monad API is a type class that takes the constructor for the underlying data type as a parameter. In Scala this separation is less well exposed. The monadic API is organized as a trait (FilterMonadic) and folded into the data constructor type. The simplest example would be to have duplicate container-like structure, such as a pair of containers serving as components of some larger structure, either of which would serve to support the monadic API for the larger structure.

Discussion of Conway games A Conway game can be thought of as a representation of a game at a given state of play. Then we could provide some simple concrete implementations as Now, we see that this definition is perfectly well founded. On to addition! Scala> Recap of the monad API. An unofficial guide to sbt 0.10. Version 2.0When the original version was published on 06/19/2011, the motive for writing this guide was to aid the effort of moving people over to sbt 0.10 from 0.7, inspired by Mark's sbt 0.10 demos that I was able to see live (first at northeast scala, and second at scala days 2011). At the time, the plugins were considered to be a major roadblock to the migration, since build users can't move to 0.10 without the plugins. So my strategy was to port the plugins myself if they weren't there, ask questions on the mailing list when I get stuck, and write up the results. I've gotten many positive feedbacks, and it's helped people get on to 0.10.

However, as it turns out, my understanding of sbt 0.10 wasn't always complete, and downright wrong and misleading at times. Don't panic If you've just landed from 0.7 world, sbt 0.10 is overwhelming. Three representations There are three ways you may interact with sbt 0.10, which could be confusing at first. the basic concepts (key-value) super class. The Essence of the Iterator Pattern - A++ [Eric Torreborre's Blog] "The Essence of the Iterator Pattern"(EIP) is the paper I liked the most last year. It gave me a brand new look over something which I had be using for years: the for loop. In this post I'll try to present some ideas of that paper and show how to implement the solution described by the authors using Scalaz-like code. A minimum previous exposure to functional programming, functors and monads will definitely help! What's in a for loop? That was really what hooked me. What do you mean "what's in a for loop"?.

Is there anything magic in that construct I've been using for years? The introduction of EIP shows an example of a for loop to iterate on elements (not the C-like for used with an index). Val basket: Basket[Fruit] = Basket(orange, apple) var count = 0 val juices = Basket[Juice]() for (fruit <- basket) { count = count + 1 juices.add(fruit.press) } We start from a "container" of fruits: Basket. And this for loop is actually not the most complex: The Applicative typeclass What is a Functor? Scala/Mustache: Creating a comma separated list. 1inShare We’re using the Mustache templating engine on my project at the moment and one thing that we wanted to do was build a comma separated list. Mustache is designed so that you pretty much can’t do any logic in the template which made it really difficult to do what we wanted. It’s easy enough to get a comma after each item in a list with something like the following code: 1.

{{#people}}<a href="/link/to/{{toString}}">{{toString}}</a>{{/people}} where people is passed to the template as a collection of strings. To get rid of the trailing comma we ended up building a collection of Pairs containing the person’s name and a boolean value indicating whether or not to show the comma. We need to show the comma before every element except for the first one so we can pass the following collection to the template: 1.val values = names.zipWithIndex.map { case(item, index) => if(index == 0) (item, false) else (item, true) } 1.

It’s truly horrendous so if anyone knows a better way then please let me know! Apache Camel and Scala: A Powerful Combination. I really like the integration framework Apache Camel and I also like Scala a lot. This article shows the basics of this combination. It is NO introduction to Apache Camel or Scala. I created a Git project to use it as simple startup for Camel-Scala-Maven projects using just the basic Camel concepts and only a few complex Scala features (i.e. very „Java-friendly“).

Problems when Starting with this Combination I had several problems finding good resources for starting when I first tried to combine them. I could not get them ready to run in IntelliJ IDEA (and Eclipse Scala plugin is still not really stable, at least on my Mac). Nevertheless, it is also tough to create a Camel project (and even more a Camel Scala project) from scratch without Maven because of so many dependencies. You can download the whole project from Github at Camel and Scala Concepts shown in this Example CamelContext You use the CamelContext as you do in Java.

Routes Testing. How to use Scala and Lucene to create a basic search application – @sologco. How to use Scala and Lucene to create a basic search application. One of the powerful benefits of Scala is that it has full access to any Java libraries; giving you a tremendous number of available resources and technology. This example doesn’t tap into the full power of Lucene, but highlights how easy it is to incorporate Java libraries into a Scala project.

This example is based off a Twitter analysis app I’ve been noodling on; which I am utilizing Lucene. The code below takes a list of tweets from a text file; creates an index that you can search and extract info from. All code and working demo app available here: Create the Index For this example, the data are simply lines in a file; each line is a tweet to be indexed. Retrieve Popular Terms from Index This example extracts the terms from the index and sorts them based on frequency count. Search Index An example of a basic search using Lucene’s term query. I hope you found it useful. Like this: A crash course in Scala types » Scalabound. After many years of Java development, discovering Scala’s type system and related features was something of a departure for me. Suffice to say GADT wasn’t my first four letter utterance when learning about pattern matching on types, let alone what, when and how to use variance annotations and generalized type constraints.

To kick things off, here’s a ‘small but powerful‘ few lines of buzzword bingo on the type system: …Scala is a statically, strongly, typed language, with implicit type inference and support for structural and existential types. It also features parameterized types, abstract and phantom types and is capable of implicitly converting between datatypes. These core capabilities are utilized by context and view bounds and complimented by generalized type constraints, to provide powerful compile time contracts. In a word, Ouch ! In the remainder of this post, I’ll try to demystify these concepts and sew the seeds of intrigue for further investigation. And again, Ouch !

House ! Scala’s Popularity on the Rise in Boston: sbt for Android | Bostinnovation: Boston Innovation, Start-ups and Tech News. Scala Documentation Rant… « GridGain – High Performance Cloud Computing. There was a recent discussion on Scala group list about using students and volunteers (yes, coming from $3M funded company) to work on some less sexy stuff like… missing documentation for the core Scala libraries. You can see full discussion here: Let me show what I have to deal with almost on the daily basis when working with Scala.

This is rather trivial example – but very telling as towards dismal quality of Scala documentation (or practically non-existence of such in many cases). I was looking at the code like that: There was an obviously missing error handling (what if str is not well formatted integer). So I looked at StringLike‘s definition of toInt method. It was empty. OK… I opened the source code for StringLike and saw that toInt simply delegates to java.lang.Integer.parseInt(...) method (without a shred of Scaladoc on it): Nice. Like this: Like Loading... ScalaDays 2011 Resources - Scala Wiki - Scala Wiki. Below, you'll find links to any publicly-available material relating to presentations given at ScalaDays 2011. This includes, but is not limited to: slidesvideosprojects referencedsource codeblog articlesfollow-ups / corrections The summary information is taken from the official ScalaDays 2011 website Please feel free to add anything that you've noticed is missing.

Articles "Fascinating But Recap by Martin Odersky Martin presented a talk on 'Future-proofing Scala collections' at the Stanford EE Computer Systems Colloquium. Slides | Video (bottom of page) Keynote: Martin Odersky - State of Scala Scala is a unique combination of cutting-edge programming language research and down-to-earth practicality. In my talk, I will give an outline of recent developments of the language and its ecosystem, and also will introduce some of the projects that are currently underway. WS Session 1 MUTS: Native Scala Constructs for Software Transactional Memory Philipp Haller and Heather Miller Zach DeVito Kevin Brown. Scala Labs - Learning Scala. Taking JavaFX for a spin.

So it’s been about 2 weeks ago when a JavaFX beta was released to the public and I could not resist to bring up some Windows and give it a try. First of all I’m quite impressed on the features it gives me compared to what I know from SWT and Swing. I can control almost L&F stuff using CSS. The first thing I did naturally was to get Eclipse Databinding integrated so that I was able to bing my EMF-Objects to it (took me half a day to implement a Value-Property-Binding) and so I can now write code like this: I know JFX comes with its own binding solution but JFX-Folks do you really think I’ll clutter my Domain-Model with your custom observable system (or did I get this wrong), what if i want to reuse it in areas no JFX is available? Anyways Eclipse Databinding works like a charme and so I don’t care about their custom JFX-Solution when I have to bind my model-instances.

So this is the UI I’ve written without CSS: And with some CSS (you know I’m not a graphic artist): Like this: Like Loading... Implement your own Scala collection. In Scala there are two families of collections: mutable and immutable ones. When you operate on a mutable collection, you change it in place, as a side effect. On the other hand, an immutable collection doesn't change but rather returns a new collection with the update you performed. Right now, the Scala library provides an immutable TreeSet but not its mutable counterpart. Let's see how to integrate our own. Preliminary choices Since it's a tree based set implementation, it would be a shame not to make it sorted.I'm really interested in exploring assets and liabilities of immutable data structures. So although the API is exposing a mutable collection, the underlying tree will be immutable.

Implementation & integration The first step in order to integrate the collection is to extend the right base trait(s). In order to allow reusability of methods shared by distinct collections, the Scala collection convention is factor them in traits suffixed by 'Like'. AVL Tree Iterator Bounded view. Move - GitHub. Scala: The Static Language that Feels Dynamic. 10 Scala One Liners to Impress Your Friends | solog. Scala « Mundo Funcional. Java EE 6 and Scala » Source Allies Blog. Setup - simple-build-tool - A build tool for Scala. S-99: Ninety-Nine Scala Problems. Scala and quartz DSL « Ouertani. Hammurabi - A Scala Rule Engine. Actor-Based Continuations with Akka and Swarm | Earl Douglas. A Year Of Scala « blog.joa-ebert.com – Blog of Joa Ebert.

Using JBoss Rules (Drools) in Scala (Richard Clayton) Access Modifiers: Scala & Java « All-Code-Edges: Java, Scala and Design Patterns. Scala.Either - Stefan's Posterous. Scala Collections and Higher-Order Functions - Stefan's Posterous. Functional Scala: High, Higher, Higher Order Functions. Introduction to Category Theory in Scala | Heiko's Blog. "Intro to Scala for Java Programmers": slides, code, and links. Exploring scalaz. Functional Scala: Comprehending Comprehensions. Functional Scala: Closures. The power of Lists in Scala « All-Code-Edges: Java, Scala and Design Patterns.

Design Patterns in Scala. Querying a Dataset with Scala's Pattern Matching. Scala exercise 6: Tackling the Wicket hierarchy mismatch problem « Kent Tong's personal thoughts on information technology. Functional Scala: Functions as Objects as Functions. Specification Pattern by Scala. Niche for Scala « Igor Artamonov. The Joy of Scala. Specification scala pattern. More Scala Scripting. Node.js and Scala without mediators « Vasil Remeniuk's Blog. Scala Bowling - A better Java or a Research Project? Scala: Implementing Factory « All-Code-Edges: Java, Scala and Design Patterns. Level Programming in Scala, Part 8a: KList motivation « Apocalisp. Level Programming in Scala, Part 6g: Type-indexed HLists « Apocalisp.

Level Programming in Scala, Part 7: Natural transformation literals « Apocalisp. Why Scala's Option won't save you from lack of experience. Scala's Option will save you from the most common cause of NullPointerException. Type-Level Programming in Scala, Part 6f: Deriving type class instances through HLists. Scala exercise 3: decorator and composite design patterns « Kent Tong's personal thoughts on information technology. Scala: Overloading Operators « Blog about Java EE Development. Scalatra | A tiny, Sinatra-like web framework for Scala. Scalatra: A Sinatra-like Web Framework for Scala. Source Forum - View Thread - Querydsl Scala design issues. Scala exercise 2: observer design pattern « Kent Tong's personal thoughts on information technology. 4.  Scala and Lift (Oracle GlassFish Server 3.0.1 Scripting Framework Guide) - Sun Microsystems. My First Scala Servlet (with Eclipse) Blog: SQL queries in Scala. Scala: Arrays, Lists, Sets and Maps « Blog about Java EE Development.

Scala exercise 1: template method design pattern « Kent Tong's personal thoughts on information technology. Scala exercise 1: template method design pattern. Blog: Querying with Scala. Scala: Hello World! « Blog about J2EE Development. Lift Web Framework :: 2.1 GA. Domain Models - Thinking differently in Scala & Clojure. JavaOne 2010: Functional Programming, from Java to Scala. A really Simple introduction to Actors for a Java Programmer « Kaushik Sathupadi.

Why Functional Programming Matters - An exploration of functional Scala. Uniscala Granite: A Wicket/db4o/Scala Web Stack. ScalaTest. I Am Chris - A Look at How Scala Compiles to Java. Package Objects. Continuation-passing style. Actors: Object Orientation Evolved. Episode 16 – Scala and Akka an Inteview with Jonas Boner. Graham Hacking Scala. Scala: Easier to read (and write), harder to understand? NoSQL Databases - NoSQL Databases - Scala with MongoDB. Forget Java, Get on Scala for Android. Learning Scala. What's New in Scala 2.8: Collections API. Is Scala Complex? Yes ... and? Scala is for VB programmers. Using generalized type constraints - How to remove code with Scala 2.8. Programming in Scala. The “Scala is too Complex” Conspiracy.