0
Upcoming SlideShare
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Standard text messaging rates apply

# fanscala1 2 scalaの基本

1,001

Published on

Published in: Technology
4 Likes
Statistics
Notes
• Full Name
Comment goes here.

Are you sure you want to Yes No
• Be the first to comment

Views
Total Views
1,001
On Slideshare
0
From Embeds
0
Number of Embeds
5
Actions
Shares
0
3
0
Likes
4
Embeds 0
No embeds

No notes for slide

### Transcript

• 1. 初心者Scala in F@N 第一回初心者
• 2. orscala
• 3. scala REPL
• 4. scala> val i = 1 + 1i: Int = 2scala> i = 1 + 3 イミュータブル（再代入できない）scala> var j = 1 + 1j: Int = 2scala> j = 1 + 3j: Int = 4 ミュータブル（再代入できる） 同じ変数に違う値を再代入するなんてバグ発生の元になるだけだから しない方がいいよという考え方
• 5. scala> val i:Int = 1 + 1i: Int = 2scala> val i = 1 + 1i: Int = 2 iの型を省略できる → 1 + 1の結果からiはInt型になるだろうと推論している （型推論）
• 6. メソッドと関数scala> def addOne(x: Int): Int = x + 1addOne: (x: Int)Intscala> val addOne = (x: Int) => x + 1addOne: (Int) => Int = <function1>scala> addOne(1)res1: Int = 2
• 7. カリー化scala> def multiply(m: Int)(n: Int): Int = m * nscala> multiply(2)(3)scala> val timesTwo = multiply(2) _scala> timesTwo(3)
• 8. List定義scala> val list = List(1, 2, 3, 4, 5)list: List[Int] = List(1, 2, 3, 4, 5)
• 9. List mapscala> list.map((i: Int) => i * 2)---javaList<Integer> result = new ArrayList<>();for(int i = 0; i < list.size; i++) { result.add(list.get(i) * 2);}
• 10. List mapscala> list.map((i: Int) => i * 2)scala> list.map(_ * 2)scala> val f = (i: Int) => i * 2scala> list.map(f)
• 11. List foreachscala> list.foreach(println(_))
• 12. List filterscala> list.filter(_ % 2 == 0)
• 13. List zipscala> val list2 = List(6, 7, 8, 9, 0)scala> list.zip(list2)
• 14. List partitionscala> list.partition((_ % 2 == 0))
• 15. List foldLeft,foldRightscala> list.foldLeft(0)((m: Int, n: Int) => m + n)scala> list.foldLeft(0)(_ + _)res28: Int = 15scala> list.foldRight(0)((m: Int, n: Int) => m + n)scala> list.fold Right(0)(_ + _)res28: Int = 15