Skip to Content
자바에서 코틀린으로
book

자바에서 코틀린으로

by 덩컨 맥그레거, 냇 프라이스, 오현석
November 2022
Beginner to intermediate
544 pages
12h 39m
Korean
Hanbit Media, Inc.
Content preview from 자바에서 코틀린으로
252
자바에서 코틀린으로
.takeWhile(translation -> !translation.equalsIgnoreCase(“STOP”))
.collect(toList());
}
이 코드를 이와 동등한 이터러블 식으로 바꿀 수 있다.
fun translatedWordsUntilSTOP(strings: List<String>): List<String> =
strings
.map { translate(it) }
.takeWhile { !it.equals(“STOP”, ignoreCase = true) }
하지만 이렇게 바꾸면 입력 리스트의
모든
단어를
map
을 사용해 다른 리스트로 바꿔야 한다.
심지어
STOP
이라는 문자열 뒤에 있는 단어도 모두
map
을 통해 변환된다.
Sequence
를 사용하
면 반환할 필요가 없는 문자열은 변환하지 않는다.
fun translatedWordsUntilSTOP(strings: List<String>): List<String> =
strings
.asSequence()
.map { translate(it) }
.takeWhile { !it.equals(“STOP”, ignoreCase = true) }
.toList()
지연 계산이 필요하지 않거나 컬렉션이 작거나 처음부터 코틀린으로 코드를 작성한다면,
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.
Start your free trial

You might also like

고성능 파이썬(2판)

고성능 파이썬(2판)

오현석, 미샤 고렐릭, 이안 오스발트
러닝 타입스크립트

러닝 타입스크립트

조시 골드버그
실리콘밸리 리더십

실리콘밸리 리더십

김정혜, 마이클 롭

Publisher Resources

ISBN: 9791169210447