Instance | Branch |
---|
package com.labex; | |
import java.sql.*; | |
public class JdbcTest { | |
// JDBC driver name | |
static final String JDBC_DRIVER = "com.mysql.jdbc.Driver"; | |
//database url | |
static final String DB_URL = "jdbc:mysql://localhost/example"; |
import javax.persistence.EntityManager; | |
import com.google.inject.AbstractModule; | |
import com.google.inject.Inject; | |
import com.google.inject.Singleton; | |
import com.google.inject.persist.PersistService; | |
import com.google.inject.persist.jpa.JpaPersistModule; | |
public class DatabaseModule extends AbstractModule { | |
#!/bin/bash | |
# | |
# Cleans all target directories. | |
# | |
# Just `sbt clean` won't remove all downloaded and/or compiled classes and .jars, and this may | |
# result in compilation exceptions when moving between branches with different dependencies. | |
# | |
set -o nounset -o errexit | |
find . -name 'target' | grep '/target$' | awk '{print "rm -Rf " $1 "/*"}' | sh |
scala> val PATTERN = """\s*SELECT\s+(.+?)\s+FROM\s+(.+?)(\s+WHERE\s+(.+?))?\s*""".r | |
PATTERN: scala.util.matching.Regex = \s*SELECT\s+(.+?)\s+FROM\s+(.+?)(\s+WHERE\s+(.+?))?\s* | |
scala> "SELECT a,b FROM t WHERE c=1,d=2" match {case PATTERN(f, t, _, c) => println(s"|$f|$t|$c|")} | |
|a,b|t|c=1,d=2| | |
scala> " SELECT a,b FROM t " match {case PATTERN(f, t, _, c) => println(s"|$f|$t|$c|")} | |
|a,b|t|null| |
-- Functional parsing library from chapter 13 of Programming in Haskell, | |
-- Graham Hutton, Cambridge University Press, 2016. | |
module Parsing (module Parsing, module Control.Applicative) where | |
import Control.Applicative | |
import Data.Char | |
-- Basic definitions |
object Main { | |
/* | |
input: data = [ | |
[1487799425, 14, 1], | |
[1487799425, 4, 0], | |
[1487799425, 2, 0], | |
[1487800378, 10, 1], | |
[1487801478, 18, 0], | |
[1487801478, 18, 1], | |
[1487901013, 1, 0], |
// given | |
def getFriends(id: Id): Set[Id] = ??? | |
// implement suggestions for friends who have the most mutual friends with user | |
def suggestedFriends(id: Id, limit: Int): Set[Id] = { | |
require(limit > 0) | |
require(id != null) | |
val friends = getFriends(id) | |
val friendsOfFriends = |
Every application ever written can be viewed as some sort of transformation on data. Data can come from different sources, such as a network or a file or user input or the Large Hadron Collider. It can come from many sources all at once to be merged and aggregated in interesting ways, and it can be produced into many different output sinks, such as a network or files or graphical user interfaces. You might produce your output all at once, as a big data dump at the end of the world (right before your program shuts down), or you might produce it more incrementally. Every application fits into this model.
The scalaz-stream project is an attempt to make it easy to construct, test and scale programs that fit within this model (which is to say, everything). It does this by providing an abstraction around a "stream" of data, which is really just this notion of some number of data being sequentially pulled out of some unspecified data source. On top of this abstraction, sca
There exist several DI frameworks / libraries
in the Scala
ecosystem. But the more functional code you write the more you'll realize there's no need to use any of them.
A few of the most claimed benefits are the following:
- Dependency Injection.
- Life cycle management.
- Dependency graph rewriting.