Scala
Completed
-
Section 1: Getting Started
-
Section 2: Core Syntax
-
Section 3: Object-Oriented Scala
-
Section 4: Functional Scala
-
Section 5: Collections in Depth
-
Section 6: Type System
-
Section 7: Concurrency and Ecosystem
-
Section 8: Practical Projects
-
Section 9: Interview Practice
-
Section 10: Data Structures and Algorithms in Scala
-
Section 11: More Practice Exercises
-
Section 12: Advanced Functional Patterns
-
Section 13: More Ecosystem
-
Section 14: Scala Collections Library Deep Dive
-
Section 15: Scala Standard Library Deep Dive
-
Section 16: Akka Ecosystem Deep Dive
-
Section 17: Cats and Cats Effect Deep Dive
-
Section 18: Play Framework Deep Dive
-
Section 19: Apache Spark with Scala Deep Dive
-
Section 20: Scala Build Tools Deep Dive
-
Section 21: Scala 3 Specific Features
-
90: Union and Intersection Types
-
Section 22: Scala Testing Deep Dive
-
Section 23: Functional Domain Modeling
-
Section 24: More Data Structures and Algorithms in Scala
-
Section 25: Scala for Data Engineering
-
Section 26: More Practical Projects
-
Section 27: More Interview and Review
-
Section 28: ZIO Ecosystem Deep Dive
-
Section 29: Scala for Machine Learning
-
Section 30: Scala Microservices Architecture
-
Section 31: Scala Type System Deep Dive
-
Section 32: More Practice and Drills
-
Section 33: Scala Performance Deep Dive
-
Section 34: Scala Ecosystem Tooling
-
Section 35: Scala for Reactive Systems
-
Section 36: More Real-World Case Studies
-
Section 37: Scala for Financial Systems
-
Section 38: Scala GraphQL and gRPC
-
Section 39: More Final Projects
-
Section 40: More Interview and Final Review
-
Section 41: Scala for Streaming Data
-
Section 42: Scala Security Practices
-
Section 43: More Language Deep Dive
-
Section 44: Scala Command-Line Tools
-
Section 45: Scala Documentation and Style
-
Section 46: Scala Dependency Management
-
Section 47: More Practical Backend Patterns
-
Section 48: Scala for Event-Driven Architecture
-
Section 49: More Practice Drills Round 2
-
Section 50: Scala Compiler Deep Dive
-
Section 51: Scala for Web Frontends
-
Section 52: More Data Engineering Practice
-
Section 53: Scala Observability
-
Section 54: More Advanced Practice Projects
-
Section 55: Scala for Legacy Java Integration
-
Section 56: More Testing Practice
-
Section 57: Final Mastery Review
-
Section 58: Scala History and Ecosystem Context
-
Section 59: More Concurrency Patterns
-
Section 60: Scala for Configuration Management
-
Section 61: More Domain Modeling Practice
4: Using the Scala REPL
Wait, why bother with the REPL if I can just write a .scala file?
I've seen a lot of developers ignore the REPL because they're used to the "write-compile-run" cycle of Java or C#. But in Scala, the REPL (Read-Eval-Print Loop) is your best friend for rapid prototyping. Think of it as a scratchpad. If I'm not 100% sure how a specific collection method like groupBy or foldLeft behaves with a weird edge case, I'm not going to spin up a whole project, create a main method, and wait for a build tool to compile everything just to test one line of code.
For example, if I want to see exactly what happens when I filter a list of strings based on a regex, I just pop open the REPL and go:
scala> val emails = List("test@example.com", "invalid-email", "dev@scala.org")
scala> emails.filter(_.contains("@"))
res2: List[String] = List(test@example.com, dev@scala.org)
It's instant. I get a result immediately without the boilerplate. Once I know the logic works, then I move it into my actual source code.
Can I define actual functions and classes in here, or is it just for one-liners?
You can absolutely define full structures. The REPL isn't just a calculator; it's a fully functional Scala environment. I often use it to sketch out case classes to see if my data model makes sense before I commit it to a file. When you define something in the REPL, it stays in the session's memory until you exit.
Check this out:
scala> case class User(name: String, age: Int)
scala> def isAdult(u: User): Boolean = u.age >= 18
scala> val bob = User("Bob", 20)
scala> isAdult(bob)
res5: Boolean = true
I just defined a data model and a piece of business logic in seconds. I personally find this invaluable when I'm learning a new library—I can import a class, instantiate it, and call methods on it to see what's actually happening under the hood without guessing based on the documentation.
How do I handle multi-line blocks without it executing too early?
This is usually where people get frustrated. If you hit enter on a line that isn't "complete" (like an open curly brace), the REPL is smart enough to know you aren't finished. It will change the prompt from scala> to *, indicating it's waiting for you to close the block.
If you're writing a slightly longer function, just keep typing:
scala> def greet(name: String) = {
* val message = s"Hello, $name!"
* println(message)
* }
scala> greet("Alice")
Hello, Alice!
res8: Unit = ()
But here is a pro tip: if you have a large chunk of code copied from a document or a website, typing it manually is a pain and prone to errors. Use the :paste command. Type :paste, hit enter, paste your entire block of code, and then hit Ctrl+D (on Unix) or Ctrl+Z (on Windows) to tell the REPL you're done. It'll evaluate the whole block at once. It saves me a ton of time when I'm sharing snippets with teammates.
📋 Practical Task
Validating a Domain-Specific String Parser in the REPL
Imagine you are building a system that processes product SKUs. The rule is that a valid SKU must start with "PROD-", be exactly 12 characters long, and end with a number.
Instead of writing a full application, use your Scala REPL to prototype the validation logic. Complete the following steps:
- Start your Scala REPL.
- Define a
case class Product(sku: String). - Define a function
def isValid(p: Product): Booleanthat implements the three rules mentioned above (starts with "PROD-", length of 12, ends with a digit). - Test your function with at least three different inputs: one that is perfectly valid, one that is too short, and one that doesn't end in a number.
Once you have the isValid function returning the correct booleans for all three test cases, you've successfully used the REPL to verify your logic!
There are no comments for now.