From 4a5137735e1f9c3b76e23fd35e1fa3cc43c65255 Mon Sep 17 00:00:00 2001 From: Max Coplan Date: Wed, 6 Nov 2019 18:54:59 -0500 Subject: [PATCH] Add information about unapply method The documentation currently just states "we're calling the unapply method", without giving any indication to *how* it's being called. Saying something like "we're calling the unapply method with `CustomerID.unapply(customer1ID)`" or "we're calling the unapply method with `name=CustomerID.unapply(customer1ID)`", while maybe not strictly accurate, helps give readers a better understanding of what's going on. I know for me personally I found this very confusing, and a line or two about this would have been very helpful. --- _tour/extractor-objects.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/_tour/extractor-objects.md b/_tour/extractor-objects.md index 345899aec3..b4156abd13 100644 --- a/_tour/extractor-objects.md +++ b/_tour/extractor-objects.md @@ -32,7 +32,7 @@ customer1ID match { } ``` -The `apply` method creates a `CustomerID` string from a `name`. The `unapply` does the inverse to get the `name` back. When we call `CustomerID("Sukyoung")`, this is shorthand syntax for calling `CustomerID.apply("Sukyoung")`. When we call `case CustomerID(name) => println(name)`, we're calling the unapply method. +The `apply` method creates a `CustomerID` string from a `name`. The `unapply` does the inverse to get the `name` back. When we call `CustomerID("Sukyoung")`, this is shorthand syntax for calling `CustomerID.apply("Sukyoung")`. When we call `case CustomerID(name) => println(name)`, we're calling the unapply method with `CustomerID.unapply(customer1ID)`. Since a value definition can use a pattern to introduce a new variable, an extractor can be used to initialize the variable, where the unapply method supplies the value.