일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
- Storm
- 엘라스틱서치
- intellij
- Angular2
- Java
- DDD
- Spring
- elasticsearch
- Spring XD
- hdfs
- Spring Batch
- Domain Driven Design
- Spring Boot
- Clean Code
- SBT
- spark
- 스프링 배치
- nginx
- Hbase
- docker
- design pattern
- elastic search
- hadoop
- scala
- 제주
- hibernate
- Gradle
- Linux
- 도메인주도설계
- apache storm
- Today
- Total
목록2016/11/02 (3)
욱'S 노트
스칼라는 NESTED 함수 정의를 지원한다. 다음은 입력된 ArrayBuffer에서 특정값을 필터링하는 예제이다.import scala.collection.mutable.ArrayBuffer object NestedFunctionTest extends App { def filter(list : ArrayBuffer[Int], filterValue : Int) = { def filterInternal(list : ArrayBuffer[Int]) = { val results = ArrayBuffer[Int]() list.foreach(i => if (i != filterValue) results += i) results } filterInternal(list) } println(filter(ArrayBuff..
스칼라에서는 고차함수 정의를 지원한다. 함수는 다른 함수를 파라미터로 전달받고 그것을 활용할 수 있다. 고차함수를 사용하는 예제는 다음과 같다.(f1 : (Int, Int) => Int, x : Int, y : Int, z : Int) => f1(x, y) * z해당 함수는 함수를 인자로 받고 함수의 결과에 곱하기를 하는 함수이다. 다음은 실제 사용예이다.object HighOrderFunctionTest extends App { val plus = (x : Int, y : Int) => x + y val minus = (x : Int, y : Int) => x - y val multiply = (f1 : (Int, Int) => Int, x : Int, y : Int, z : Int) => f1(x, ..
스칼라에서 익명함수를 정의하는 방법은 매우 간단하다. 아래는 가장 간편하게 정의한 예이다. 왼쪽부분은 파라미터를 정의한 부분이고 오른쪽 부분의 수식을 정의한 부분이다.(x: Int) => x + 1위의 익명함수는 사실 아래와 같은 정의를 단순한 한 것이다.new Function1[Int,Int] { override def apply(x: Int): Int = x + 1 }다수의 파라미터의 경우는 아래와 같이 정의한다.(x: Int, y:Int) => x + y파라미터가 없는 경우는 다음과 같다.() => System.getProperty("user.dir")위의 각 함수들을 테스트하면 아래와 같이 수행할 수 있다.object FunctionTest extends App { val plusOne = (x:..