You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
println("i'm guessing your number is zero or less")
1009
+
}
1010
+
```
1011
+
{% endtab %}
1012
+
{% tab 'Scala 3' for=control-structures-31 %}
1013
+
```scala
1014
+
count match
1015
+
case1=>
1016
+
println("one, a lonely number")
1017
+
case x if x ==2|| x ==3=>
1018
+
println("two's company, three's a crowd")
1019
+
case x if x >3=>
1020
+
println("4+, that's a party")
1021
+
case _ =>
1022
+
println("i'm guessing your number is zero or less")
1023
+
```
1024
+
{% endtab %}
1025
+
{% endtabs %}
1026
+
1027
+
In Scala 3, `match` expressions can be chained:
1028
+
1029
+
{% tabs 'control-structures-32' %}
1030
+
{% tab 'Scala 3 Only' %}
1031
+
```scala
1032
+
i match
1033
+
caseodd: Intif odd %2==1=>"odd"
1034
+
caseeven: Intif even %2==0=>"even"
1035
+
case _ =>"not an integer"
1036
+
match
1037
+
case"even"=>true
1038
+
case _ =>false
1039
+
```
1040
+
{% endtab %}
1041
+
{% endtabs %}
999
1042
1000
1043
## try/catch/finally
1001
1044
@@ -1004,8 +1047,8 @@ For consistency, Scala uses the same syntax that `match` expressions use and sup
1004
1047
1005
1048
In the following example, `openAndReadAFile` is a method that does what its name implies: it opens a file and reads the text in it, assigning the result to the mutable variable `text`:
Where the previous chapter introduced Scala *methods*, this chapter digs into *functions*.
13
-
The topics that are covered include anonymous functions, function variables, and higher-order functions (HOFs), including how to create your own HOFs.
13
+
The topics that are covered include anonymous functions, partial functions, function variables, and higher-order functions (HOFs), including how to create your own HOFs.
Copy file name to clipboardExpand all lines: _overviews/scala3-book/packaging-imports.md
+1-1
Original file line number
Diff line number
Diff line change
@@ -3,7 +3,7 @@ title: Packaging and Imports
3
3
type: chapter
4
4
description: A discussion of using packages and imports to organize your code, build related modules of code, control scope, and help prevent namespace collisions.
0 commit comments