val splitOnComma: (String) -> List<String> = { line ->
line.splitFields(“,”)
}
분할 함수를 정의할 때마다 매번 람다를 정의하지 않아도 된다면 좋을 것이다. 이런 방식
을 제공하면 프랑스 클라이언트들은
splitter
=
splitOn
(“;”)
같이 파라미터를 지정해
readTable
을 호출할 수 있다. 이
splitOn
함수는 구분자를 인자로 받아서
(
String
) ->
List
<
String
>
라는 함수 타입의 값을 반환한다. 이 함수를 현재의
splitOnComma
람다로부터
추출하려고 시도할 수도 있지만, 리팩터링이 지겨우므로 그냥 직접 함수를 정의하고 호출하자.
예제
22.52
[
table
-
reader
.
37
:
src
/
main
/
java
/
travelator
/
tablereader
/
table
-
reading
.
kt
]
fun splitOn(
separators: String
): (String) -> List<String> = ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month, and much more.