Whole-book reading guide from stratified index samples; jump to passages in the text
Tip the Site
Support this siteYour recognition and a small knowledge-service contribution help keep this technical work open source.Scan the WeChat Pay or Alipay code below. Logged-in and guest visitors can both tip.
WeChat Pay
Alipay
Open WeChat or Alipay and scan. No login required.
AI guide
【One-Line Pitch】
A practical, example-driven guide to writing idiomatic Kotlin in a functional style—lambdas, function references, collection pipelines, sequences, and DSL builders—for developers who already know Kotlin basics and want to make their code shorter, safer, and more expressive.
【Book Arc】
- **Opening (~0%–12%)**: Frames Kotlin as a pragmatic hybrid—rich functional features (function types, lambdas, immutability, expressions, lazy evaluation) without the purity of Haskell or Scala—and sets up the vocabulary the rest of the book relies on.
- **Early (~12%–35%)**: Builds the toolkit of functions-as-values: lambda expressions, anonymous functions, function references (including constructor and property references), functional interfaces/SAM conversion, and inline functions for performance.
- **Middle (~35%–55%)**: The collection-processing core—filter, map, fold/reduce, any/all/none, partition, groupBy, distinct, sorting, min/max, random/shuffled, zip/zipWithNext, and windowing—taught through stdlib-style implementations and realistic examples.
- **Late (~55%–75%)**: Moves from collections to sequences: what they are, why order matters, how they minimize operations, how they can be infinite, when they are *not* faster, and how they compare to Java streams.
- **Ending (~75%–100%)**: Advanced expression techniques—type-safe DSL builders with receiver function types, `DslMarker`, scope functions (`let`, `also`, `takeIf`, `apply`, `with`, `run`), and context receivers, closing with guidance on when these tools are worth the complexity.
【Key Takeaways】
- **Kotlin is functional-friendly, not purely functional** (Opening): It deliberately omits currying and partial application, favoring features that keep code understandable; libraries like Arrow fill some gaps. Knowing this framing prevents you from expecting Haskell-style purity.
- **Functions are first-class objects with real types** (Early): Function types, lambdas, anonymous functions, and references (`::foo`, `::Class`, `obj::method`, property getters) are interchangeable ways to express behavior—choose based on clarity, not habit.
- **Lambdas vs. anonymous functions is a readability trade-off** (Early): Lambdas win on brevity (trailing lambda, implicit `it`, labeled returns like `return@onUserChanged`), while anonymous functions make explicit `return` and result types clearer for longer bodies.
- **Inline functions resolve the performance cost of higher-order functions** (Early): Marking functions like `fold` as `inline` gives both convenience and speed; extension properties can be inlined too.
- **Collection pipelines replace loops with declarative steps** (Middle): `filter`/`map`/`fold`/`reduce`/`partition`/`groupBy`/`distinct`/`zip`/`windowed` each express one transformation, and understanding their stdlib implementations (e.g., `reduce` throws on empty; use `reduceOrNull`) prevents subtle bugs.
- **Sequences trade memory for control—and aren't always faster** (Late): They avoid intermediate collections, support infinite streams, and minimize operations when order is right, but the book explicitly flags cases where plain collections outperform them.
- **DSLs are built from receiver function types plus `DslMarker`** (Ending): Multi-level builders and `apply` enable fluent APIs, but the book asks *when* DSLs are justified rather than treating them as a default.
- **Scope functions are powerful but easy to misuse** (Ending): `let`, `also`, `apply`, `with`, `run`, and `takeIf` differ mainly in receiver vs. argument and return value; careless receiver overloading is called out as a real hazard.
【Reading Tips】
- **Skim the opening if you know Kotlin already**, but read the feature-support table carefully—it's the book's thesis and shapes every later choice.
- **Deep-read the collection-processing middle**: it's the largest, most example-dense section and the highest daily-payoff material; type out the simplified stdlib implementations to internalize edge cases.
- **Treat sequences as a decision chapter, not a mandate**: focus on the "when aren't sequences faster?" discussion and the Java streams comparison.
- **Practice function references and scope functions in your own codebase**—the book notes references are worth practicing because they only feel natural with use.
- **Don't rush the DSL/context-receiver ending**: it's the most advanced and the easiest to over-apply; take away the "when should we use DSLs?" criteria rather than copying patterns.
【Coverage Limits】
These excerpts cover the book's functional-programming core (lambdas, references, collections, sequences, DSLs, scope functions) but do not include full chapter text for every topic; details on context receivers, `DslMarker` internals, and some later examples are only partially represented.
Page 14
r Kotlinwasdesigned to support functional programming (FP), but not asmuch asHaskell or Scala. However, there aremany functional programming features that it...
e of its function reference is (Double, Double) -> Complex. fun zeroComplex(): Complex = Complex(0.0, 0.0) fun makeComplex( real: Double = 0.0, imaginary: Do...
es are compiled into func- tions. val User.fullName: String get() = "$name $surname" var User.birthday: Date get() = Date(birthdayMillis) set(value) { birthd...
pValues { (_, formats) -> formats.maxOf { it.resolution } } There is also the groupingBy method, which can be used as an alternative to groupBy. groupingBy i...
l operation on this sequence, the elements are processed³². fun main() { val s = (1..6).asSequence() .filter { print("F$it, "); it % 2 == 1 } .map { print("M...
t we did not want it to be defined as an extension function. We could provide LoggingContext using a context receiver. context(LoggingContext) fun sendNotifi...
is required, as in Java⁴⁴. Another prime example of this is the copy method, which allows us to create a new version of a value based on another one, where w...
Support this siteYour recognition and a small knowledge-service contribution help keep this technical work open source.
Scan the WeChat Pay or Alipay code below. Logged-in and guest visitors can both tip.
WeChat PayAlipay
Open WeChat or Alipay and scan. No login required.
Add Tag
Enter tag name (max 50 characters)
Share E-Book
Functional Kotlin (Marcin Moskała)(Z-Library)
Scan QR code with your phone to access
Copy the link or scan the QR code to access this e-book on your phone
Share to WeChat Moments
Functional Kotlin (Marcin Moskała)(Z-Library)
Scan the QR code with WeChat to open this book
Tap the ··· menu in the top-right corner
Choose Share to Moments
You are already in WeChat. Tap ··· in the top-right corner and choose Share to Moments.
Share E-Book via Email
Please enter email address
Donation Statistics
¥.00
Total Donations
0
Donation Count
Functional Kotlin (Marcin Moskała)(Z-Library)
Find Your Favorite Books
Only registered users can comment after logging in. Comments need to be reviewed by administrators before being displayed
Loading comments...
Reply to Comment
Edit Comment