2019/05 Scala導入を検討したい人に向けた情報をまとめてみた
Scalaとは?
- The Scala Programming Language
- 開発元はLightbend 社 と EPFL(Odersky先生がいるスイスの大学)
- 2019/05 現在、最新バージョンは 2.12
- Dottyと呼ばれる新しいScalaコンパイラが開発されている
- Scala3
- 2019/05 現在0.15.0-RC1
plugins { | |
id 'org.springframework.boot' version '2.1.9.RELEASE' | |
id 'io.spring.dependency-management' version '1.0.8.RELEASE' | |
id 'java' | |
} | |
group = 'com.example' | |
version = '0.0.1-SNAPSHOT' | |
sourceCompatibility = '11' |
object FizzBuzz extends App { | |
val result = (1 to 100).map { | |
case x if x % 3 == 0 && x % 5 == 0 => "FizzBuzz" | |
case x if x % 3 == 0 => "Fizz" | |
case x if x % 5 == 0 => "Buzz" | |
case x => x | |
} | |
result.foreach(println) |
% sbt (git)-[develop] | |
ERROR: transport error 202: bind failed: Address already in use | |
ERROR: JDWP Transport dt_socket failed to initialize, TRANSPORT_INIT(510) | |
JDWP exit error AGENT_ERROR_TRANSPORT_INIT(197): No transports initialized [debugInit.c:750] | |
FATAL ERROR in native method: JDWP No transports initialized, jvmtiError=AGENT_ERROR_TRANSPORT_INIT(197) | |
/usr/local/Cellar/sbt/1.1.6/libexec/bin/sbt-launch-lib.bash: 58 行: 1934 Abort trap: 6 "$@" |
play.api.UnexpectedException: Unexpected exception[CreationException: Unable to create injector, see the following errors: | |
1) Error injecting constructor, java.lang.NoSuchMethodError: scalikejdbc.NamedDB$.apply$default$2()Lscalikejdbc/SettingsProvider; | |
at scalikejdbc.PlayFixture.<init>(PlayFixtureModule.scala:38) | |
at scalikejdbc.PlayFixtureModule.bindings(PlayFixtureModule.scala:29): | |
Binding(class scalikejdbc.PlayFixture to self eagerly) (via modules: com.google.inject.util.Modules$OverrideModule -> play.api.inject.guice.GuiceableModuleConversions$$anon$1) | |
while locating scalikejdbc.PlayFixture | |
1 error] | |
at play.core.server.DevServerStart$$anonfun$mainDev$1$$anon$1$$anonfun$get$1$$anonfun$apply$1$$anonfun$1.apply(DevServerStart.scala:170) |
[info] hello-scalikejdbc:hello-scalikejdbc_2.11:0.1 [S] | |
[info] +-com.github.tototoshi:play-json4s-native_2.11:0.5.0 [S] | |
[info] | +-com.github.tototoshi:play-json4s-api_2.11:0.5.0 [S] | |
[info] | | +-org.json4s:json4s-core_2.11:3.3.0 [S] | |
[info] | | +-com.thoughtworks.paranamer:paranamer:2.8 | |
[info] | | +-org.json4s:json4s-ast_2.11:3.3.0 [S] | |
[info] | | +-org.json4s:json4s-scalap_2.11:3.3.0 [S] | |
[info] | | +-org.scala-lang.modules:scala-xml_2.11:1.0.5 [S] | |
[info] | | | |
[info] | +-com.github.tototoshi:play-json4s-core_2.11:0.5.0 [S] |
import scala.annotation.tailrec | |
import scala.collection.immutable.TreeMap | |
val lines = List( | |
"- 2018年02月08日 木曜日 20:51", | |
"今日は仕事をしました", | |
"お昼にパスタをつくりました", | |
"- 2018年02月09日 金曜日 20:51", | |
"お出かけしました" | |
) |
val name: Option[String] = Some("きの子")
val greet = name.map(n => s"${n}さんこんにちは") // greet: Option[String] = Some(きの子さんこんにちは)
greet.getOrElse("なまえがないよ") // Optionから値をとりだした。 res1: String = きの子さんこんにちは