Skip to content

Instantly share code, notes, and snippets.

import scala.Option
class User(private val firstname: String, private val lastname: String)
object User {
def unapply(user: User) = Option((user.firstname, user.lastname))
def main(args: Array[String]): Unit = {
val user = new User("剛次", "赤石")
@f81
f81 / file0.java
Created March 31, 2014 08:10
第21章:Scalaの型パラメータ ref: http://qiita.com/f81@github/items/7a664df8f4b87d86e5d8
public class ArrayList<E> {...}
import akka.actor.ActorSystem
import akka.actor.Props
import akka.actor.Actor
import akka.routing.RoundRobinRouter
object ActorSample {
def main(args: Array[String]): Unit = {
val system = ActorSystem("helloSystem")
val router = system.actorOf(Props[HelloActor].withRouter(RoundRobinRouter(4)))
@f81
f81 / file0.scala
Last active August 29, 2015 13:56
第19章:Scalaでカリー化と部分適用 ref: http://qiita.com/f81@github/items/e8bfab96b4be9e404840
scala> val add = {(x:Int, y:Int, z:Int) => x + y + z}
add: (Int, Int, Int) => Int = <function3>
import scala.util.Random
object PatternMatchConst {
def main(args: Array[String]): Unit = {
val random = Random.nextBoolean
val num = random match {
case true => 1
case false => 0
scala> 1 + 2
res0: Int = 3
scala> 3 - 1
res1: Int = 2
scala> 4 * 2
res2: Int = 8
scala> 6 / 3
@f81
f81 / file0.txt
Created December 13, 2013 12:47
[bash] CentOS添付ファイル付きメール送信(sendmail)の実装 ref: http://qiita.com/f81@github/items/6ef614c6e88b9d17c41f
#/bin/sh
# commands.
SENDMAIL=/usr/lib/sendmail
ECHO=/bin/echo
GZIP=/bin/gzip
CAT=/bin/cat
RM=/bin/rm
# attachment file info.
object CaseClass {
def main(args: Array[String]): Unit = {
val domain1 = new Domain3(1, "富樫")
val domain2 = new Domain3(1, "富樫")
println("==:", domain1 == domain2)
println("!=:", domain1 != domain2)
val domain3 = new Domain3(2, "虎丸")
import java.io.File
object IfTest1 {
def main(args: Array[String]): Unit = {
var filename = "config.txt"
if (!args.isEmpty)
filename = args(0)
@f81
f81 / Option1.scala
Created October 28, 2013 06:56
第14章:ScalaのOption型とnullを語る ref: http://qiita.com/f81@github/items/7bca48469d9aea65780d
object Option1 {
def main(args: Array[String]): Unit = {
val map = Map(1 -> "Moses", 2 -> "Lucas", 3 -> "Henderson")
def check(o: Option[String]) {
o match {
case Some(s) => println(s)
case None => println("Not exist.")
}