Skip to content

Instantly share code, notes, and snippets.

object FirstClassFunction{
def main(args: Array[String]){
val add = (x: Int) => {
val _add = (y: Int) => y + 5
_add(x)
}
printf("add=%s \n", add(1))
printf("add=%s \n", add(2))
printf("add=%s \n", add(1))
@f81
f81 / User.java
Created June 17, 2013 02:00
But I remember オブジェクト指向 ref: http://qiita.com/items/5cbba25f1d4d7c8953e5
public class User {
private final long id;
private final String firstname;
private final String lastname;
public User(long id, String firstname, String lastname) {
this.id = id;
public class Car {
public static void main(String[] args) {
final Car car = new Car("blue");
car.run();
}
private static void output(String message) {
System.out.println(message);
}
@f81
f81 / Literal.scala
Created July 29, 2013 06:56
第6章:Scalaのプリミティブ型を語る ref: http://qiita.com/f81@github/items/c43803f4a8da94615c9c
object Literal {
def main(args: Array[String]){
// 整数リテラル
// 10進数
val dec = 24
println("dec:" + dec)
// 16進数
val hex = 0x24
println("hex:" + hex)
@f81
f81 / CaseClassTuple.scala
Created August 12, 2013 14:46
第7章:タプルにチャレンジ! ref: http://qiita.com/f81@github/items/a8419532c316d190782d
object CaseClassTuple {
def get() = {
val name = new Name("清美", "椿山")
(Human(name, 15), name)
}
def main(args: Array[String]){
val tuple = get()
printf("fullname_1=%s \n", tuple._1.name.fullname)
@f81
f81 / file0.txt
Created September 2, 2013 07:58
第8章:Scalaのコレクション(Seq, Set, Map)入門 ref: http://qiita.com/f81@github/items/dc79819d23ce4889d552
scala> val numbers = Set(1, 2, 3)
numbers: scala.collection.immutable.Set[Int] = Set(1, 2, 3)
@f81
f81 / Human.scala
Created September 16, 2013 16:14
第9章:Scalaのトレイト(trait) ref: http://qiita.com/f81@github/items/5b96af593812286eec49
trait Job {
def getName() {
"student"
}
}
@f81
f81 / file0.scala
Created September 30, 2013 07:53
第11章:Scalaの「Traversable」リファレンス ref: http://qiita.com/f81@github/items/62ad3c56ce6be271ef35
scala> Seq(1, 2, 3).foreach(print(_))
123
@f81
f81 / file0.scala
Last active December 24, 2015 06:59
第11章:ScalaのSeqリファレンス ref: http://qiita.com/f81@github/items/75c616a527cf5c039676
scala> Seq(1, 2, 3)(2)
res0: Int = 3
@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.")
}