官术网_书友最值得收藏!

Introduction

Despite the fact that Kotlin is recognized implicitly as an object-oriented language, it is still open to other programming styles and paradigms. Thanks to Kotlin's built-in features, we are able to apply functional programming patterns to our code with ease. Having the possibility to return functions from other functions or to pass a function as a parameter allows us to benefit from a deferred computation. In addition, we are able to return functions, instead of already-computed values, on different layers in the code. This results in the lazy-evaluation feature.

Compared to Scala or other functional programming languages, Kotlin doesn't require us to use dedicated, functional style design patterns. It also lacks some of their out-of-the-box implementations. However, in return, it brings more flexibility to developers as far as software architecture and implementation details are concerned. The Kotlin language and standard library components provide full built-in support for basic functional programming concepts. And more sophisticated ones can always be implemented from scratch or reused from some of the available external libraries. The ones worth giving a try are the Kotlin Arrow (http://arrow-kt.io) and funKTionale (https://github.com/MarioAriasC/funKTionale) projects. However, keep in mind the words of Robert C. Martin—It is perfectly possible to write a program that is both object-oriented and functional. Not only is it possible, it is desirable. There is no "OO vs FP," the two are orthogonal and coexist nicely. It should be understood that functional programming is only one available tool. It should be used wisely and only where it is applicable.

This chapter focuses on explaining functional programming features supported by Kotlin internally. It gives you hands-on experience in solving real-life problems by using state-of-the-art functional programming concepts. By the end of the chapter, you should be familiar with the Kotlin language support for the functional programming approach and standard library components that can help implement it.

主站蜘蛛池模板: 泾阳县| 霍山县| 栾川县| 揭东县| 静海县| 莒南县| 咸阳市| 太仆寺旗| 营山县| 霍城县| 靖江市| 雅江县| 江源县| 永春县| 兴宁市| 麻栗坡县| 高尔夫| 南开区| 玉门市| 石林| 赞皇县| 民丰县| 嘉峪关市| 融水| 东乌| 龙泉市| 张家界市| 文水县| 黎城县| 民县| 开化县| 汽车| 绵阳市| 郎溪县| 申扎县| 义乌市| 宁南县| 文水县| 监利县| 米泉市| 临高县|