- Kotlin Standard Library Cookbook
- Samuel Urbanowicz
- 128字
- 2021-07-23 19:05:58
There's more...
The Kotlin standard library uses the infix notation extensively. You can benefit from infix functions to shape your code the clean way. One infix function worth noting is the to() extension function provided for the Map.Entry<K, V> class, which allows you to declare map entries in a minimalistic way:
val namesWithBirthdays: Map<String, LocalDate> =
mapOf("Agata" to LocalDate.of(1990, 1, 18))
The to() extension function is declared for a generic type A and generic argument of type B, which returns an instance of a Pair<A, B> class.
There are plenty of other functions supporting infix notations available in the standard library. If you check the implementation of the ones you are using on a daily basis, it may turn out they are available in the infix form too.
推薦閱讀
- Django+Vue.js商城項目實戰(zhàn)
- Python程序設(shè)計教程(第2版)
- Python快樂編程:人工智能深度學習基礎(chǔ)
- 劍指Offer(專項突破版):數(shù)據(jù)結(jié)構(gòu)與算法名企面試題精講
- Cross-platform Desktop Application Development:Electron,Node,NW.js,and React
- Linux命令行與shell腳本編程大全(第4版)
- Yii Project Blueprints
- Statistical Application Development with R and Python(Second Edition)
- Extreme C
- SQL Server 入門很輕松(微課超值版)
- Flutter之旅
- Visual FoxPro程序設(shè)計實驗教程
- Swift iOS Programming for Kids
- 軟件測試
- Visual FoxPro程序設(shè)計