Skip to content

Commit 6711e0f

Browse files
committed
.
1 parent c8cdea7 commit 6711e0f

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

content/unpack.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -723,6 +723,8 @@ def magnitudeInt(unpack v: Point[Int])
723723
magnitude(x = 5, y = 3) // 4: Int
724724
```
725725

726+
This is similar to what we saw in the `os.walk` example earlier.
727+
726728
### Orthogonality
727729

728730
`unpack` on definitions and `*` on `case class` values are orthogonal: either can be used without
@@ -736,9 +738,13 @@ case class RequestConfig(url: String,
736738

737739
def downloadSimple(unpack config: RequestConfig) = ???
738740

739-
val data = downloadSimple("www.example.com", 1000, 10000)
741+
val data1 = downloadSimple("www.example.com", 1000, 10000)
742+
val data2 = downloadSimple(url = "www.example.com", connectTimeout = 1000, readTimeout = 10000)
740743
```
741744

745+
When you `unpack` a `case class`, the resulting parameters can be called via either positional
746+
or named arguments.
747+
742748
Similarly, you can define parameters individually at the definition-site and `unpack` a `case class`
743749
with matching fields at the call-site
744750

@@ -773,7 +779,7 @@ val config = OtherConfig("www.example.com", 1000, 10000)
773779
val data = downloadSimple(config*)
774780
```
775781

776-
Mix `unpack`-ed and individually passed argments:
782+
Or mix `unpack`-ed and individually passed arguments:
777783

778784
```scala
779785
case class AsyncConfig(retry: Boolean, ec: ExecutionContext)
@@ -789,6 +795,8 @@ case class OtherConfig(url: String,
789795
retry: Boolean)
790796

791797
val config = OtherConfig("www.example.com", 1000, 10000, true)
798+
// `OtherConfig` matches some of the fields from `unpack config: RequestConfig` and
799+
// `unpack asyncConfig: AsyncConfig`, and we pass the last missing `retry = true` individually
792800
downloadAsync(config*, retry = true)
793801
```
794802

0 commit comments

Comments
 (0)