命令型で記述。
for (n <- 1 to 100) {
if (n % 15 == 0) {
println("FizzBuzz")
} else if (n % 3 == 0) {
println("Fizz")
} else if (n % 5 == 0) {
println("Buzz")
} else {
import collection.mutable.ListBuffer | |
// 命令型で書いた場合 | |
val filtered = new ListBuffer[Int] | |
val numbers = List(1,2,3,4,5) | |
for(n <- numbers){ | |
if (n % 2 == 0){ | |
filtered += n | |
} | |
} |
case class Car(name: String, color: String) | |
def find(name: String, cars: List[Car]): Option[Car] = { | |
for (car <- cars) { | |
if (car.name == name) { | |
return Some(car) | |
} | |
} | |
None | |
} |
命令型で記述。
for (n <- 1 to 100) {
if (n % 15 == 0) {
println("FizzBuzz")
} else if (n % 3 == 0) {
println("Fizz")
} else if (n % 5 == 0) {
println("Buzz")
} else {
// 1. $PROJECT_ROOT/project/build/MyProject.scalaを作る。IdeaProjectをミックスインする。 | |
import sbt._ | |
class MyProject(info: ProjectInfo) extends DefaultProject(info) with IdeaProject{ | |
} | |
// 2. $PROJECT_ROOT/project/plugins/Plugins.scalaを以下のように作る。 | |
import sbt._ |
pom.xmlの中身 | |
<?xml version='1.0' encoding='UTF-8'?> | |
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> | |
<modelVersion>4.0.0</modelVersion> | |
<groupId>jp.tricreo.scala</groupId> | |
<artifactId>scala-ddd-base_2.8.1</artifactId> | |
<packaging>jar</packaging> | |
<version>0.0.1-SNAPSHOT</version> | |
... |
import sbt._ | |
class MyProject(info: ProjectInfo) extends DefaultProject(info) { | |
override def managedStyle = ManagedStyle.Maven | |
// publishing | |
lazy val publishTo = if (version.toString.endsWith("-SNAPSHOT")){ | |
println("Selected Snapshot") | |
Resolver.sftp("Tricreo Repo", "maven.tricreo.jp", "/var/www/maven.tricreo.jp/snapshot") |
package util; | |
import java.io.Serializable; | |
import java.util.Iterator; | |
public class Range implements Iterable<Integer>, Serializable, Cloneable { | |
private static class RangeIterator implements Iterator<Integer> { | |
final int start; |
import collection.mutable.ListBuffer | |
/**列挙型定数を表すトレイト。 | |
* | |
* @author j5ik2o | |
*/ | |
trait EnumEntry extends Serializable with Ordered[EnumEntry] { | |
/**列挙定数の序数 (列挙宣言での位置)。 */ | |
private[util] var ordinalNo: Int = _ |
require 'formula' | |
class Maven3 < Formula | |
url 'http://www.apache.org/dist/maven/binaries/apache-maven-3.0.3-bin.tar.gz' | |
homepage 'http://maven.apache.org/' | |
md5 '507828d328eb3735103c0492443ef0f0' | |
def install | |
# Remove windows files | |
rm_f Dir["bin/*.bat"] |
require 'formula' | |
class Maven2 < Formula | |
url 'http://www.apache.org/dist/maven/binaries/apache-maven-2.2.1-bin.tar.gz' | |
homepage 'http://maven.apache.org/' | |
md5 '3f829ed854cbacdaca8f809e4954c916' | |
def install | |
rm_f Dir["bin/*.bat"] |