일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- elastic search
- Spring Batch
- Clean Code
- Hbase
- Spring XD
- apache storm
- hdfs
- intellij
- elasticsearch
- SBT
- docker
- 스프링 배치
- DDD
- Spring Boot
- Linux
- Spring
- 일본 백패킹
- Storm
- scala
- nginx
- 엘라스틱서치
- 제주
- 도메인주도설계
- Java
- spark
- design pattern
- Angular2
- hadoop
- 인텔리J
- Gradle
Archives
- Today
- Total
욱'S 노트
Scala - 고차함수 본문
반응형
스칼라에서는 고차함수 정의를 지원한다. 함수는 다른 함수를 파라미터로 전달받고 그것을 활용할 수 있다. 고차함수를 사용하는 예제는 다음과 같다.
(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, y) * z
println(multiply(plus, 2, 3, 2))
println(multiply(minus, 10, 5, 1))
}
출처 : http://docs.scala-lang.org/tutorials/tour/higher-order-functions
반응형
'Programming > Scala' 카테고리의 다른 글
Scala - 커링 (0) | 2016.11.04 |
---|---|
Scala - 내포된 함수 (0) | 2016.11.02 |
Scala - 익명 함수 (0) | 2016.11.02 |
Scala - 믹스인 클래스 컴포지션 (0) | 2016.11.01 |
Scala - 트래잇 (0) | 2016.11.01 |