@@ -723,6 +723,8 @@ def magnitudeInt(unpack v: Point[Int])
723
723
magnitude(x = 5 , y = 3 ) // 4: Int
724
724
```
725
725
726
+ This is similar to what we saw in the ` os.walk ` example earlier.
727
+
726
728
### Orthogonality
727
729
728
730
` unpack ` on definitions and ` * ` on ` case class ` values are orthogonal: either can be used without
@@ -736,9 +738,13 @@ case class RequestConfig(url: String,
736
738
737
739
def downloadSimple (unpack config : RequestConfig ) = ???
738
740
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 )
740
743
```
741
744
745
+ When you ` unpack ` a ` case class ` , the resulting parameters can be called via either positional
746
+ or named arguments.
747
+
742
748
Similarly, you can define parameters individually at the definition-site and ` unpack ` a ` case class `
743
749
with matching fields at the call-site
744
750
@@ -773,7 +779,7 @@ val config = OtherConfig("www.example.com", 1000, 10000)
773
779
val data = downloadSimple(config* )
774
780
```
775
781
776
- Mix ` unpack ` -ed and individually passed argments :
782
+ Or mix ` unpack ` -ed and individually passed arguments :
777
783
778
784
``` scala
779
785
case class AsyncConfig (retry : Boolean , ec : ExecutionContext )
@@ -789,6 +795,8 @@ case class OtherConfig(url: String,
789
795
retry : Boolean )
790
796
791
797
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
792
800
downloadAsync(config* , retry = true )
793
801
```
794
802
0 commit comments