Skip to content

Commit 3b0f4b6

Browse files
committed
Shorten the boundary/break section in 3.3 announcement
1 parent 8e204ef commit 3b0f4b6

File tree

1 file changed

+1
-31
lines changed

1 file changed

+1
-31
lines changed

blog/_posts/2023-05-26-scala-3.3.0-released.md

+1-31
Original file line numberDiff line numberDiff line change
@@ -88,37 +88,7 @@ def sumOfRoots(number: List[Double]): Option[Double] = boundary:
8888

8989
When you run the above method, you will notice that it returns `None` when any of the input elements is negative. Moreover, thanks to `boundary`/`break`, you can see from the console output that it stops iterating after encountering the first negative element.
9090

91-
`break` can jump out of the `boundary` in the function deeper on the stack. To make it safe, only functions with a matching `Label` in their using clauses can break. This can be used to create isolated parts of an application with streamlined error handling.
92-
93-
Library authors can abstract over `break` and `Label`, creating a nice API for error handling or dealing with uncertain data. We can define the following micro-library as a simplified example:
94-
95-
```Scala
96-
import util.boundary, boundary.{ Label, break }
97-
98-
type Uncertain[T] = Label[Left[String, Nothing]] ?=> T
99-
100-
def fail(error: String): Uncertain[Nothing] = break(Left(error))
101-
```
102-
103-
Then it can be used in the following way to create a fragment of a larger application with isolated error handling:
104-
105-
```Scala
106-
def getUser(id: String): Uncertain[User] =
107-
val user = findUser(id)
108-
if verifyUser(user) then user else fail("Incorrect user")
109-
110-
def getAddress(user: User): Uncertain[Address] =
111-
findAddress(user) match
112-
case Some(address) if verifyAddress(address) => address
113-
case Some(_) => fail("Incorrect address")
114-
case None => fail("Missing address")
115-
116-
def getShippingData(id: String): Either[String, (User, Address)] =
117-
boundary:
118-
val user = getUser(id)
119-
val address = getAddress(user)
120-
Right((user, address))
121-
```
91+
`break` can jump out of the `boundary` in the function deeper on the stack. To make it safe, only functions with a matching `Label` in their using clauses can break. This can be used to create isolated parts of an application with streamlined error handling. Library authors can abstract over `break` and `Label`, creating a nice API for error handling or dealing with uncertain data.
12292

12393
### The new default implementation of lazy vals
12494

0 commit comments

Comments
 (0)