alternative syntax for unapply extractors
              
              #12793
            
            Replies: 7 comments 11 replies
-
| more accurately,   object name:
    def unapply ... | 
Beta Was this translation helpful? Give feedback.
-
| Is this different from "name-based extractors"? Edit: I see they call it "Optionless". (No hyphen required for option-less.) "De-optioned." | 
Beta Was this translation helpful? Give feedback.
-
| There could be a SAM that would let you create one with an ordinary function… On Fri, Jun 11, 2021, 12:44 PM Erik Erlandson ***@***.***> wrote:
 yet another way to express it: "extractor" is really a first-class concept
 in scala, and quite powerful, which doesn't in principal need to be tied to
 an "object" - it is an entity in its own right, and I propose it merits its
 own keyword extractor. If it remains implemented as unapply underneath an
 object of a given name, that is just a smart design strategy
 —
 You are receiving this because you are subscribed to this thread.
 Reply to this email directly, view it on GitHub
 <#12793 (reply in thread)>,
 or unsubscribe
 <https://github.com/notifications/unsubscribe-auth/AAAYAUGWNVVBZCJN3K5XPUTTSI4NPANCNFSM46Q74VEA>
 .
 | 
Beta Was this translation helpful? Give feedback.
-
| I see the explicit object is required for extension method version, otherwise "constructor proxy object C cannot be used as a value". It would help to lift that restriction for this context.  | 
Beta Was this translation helpful? Give feedback.
-
| Single Abstract Method.
trait Extractor[-A, +B] { def unapply(in: A): Option[B] }
val AsInt: Extractor[String, Int] = _.toIntOption
"10" match { case AsInt(i) => i - 1 }… On Fri, Jun 11, 2021, 12:58 PM Erik Erlandson ***@***.***> wrote:
 What is SAM ?
 —
 You are receiving this because you commented.
 Reply to this email directly, view it on GitHub
 <#12793 (reply in thread)>,
 or unsubscribe
 <https://github.com/notifications/unsubscribe-auth/AAAYAUDYKKGSYN2WRFMYDOLTSI6EZANCNFSM46Q74VEA>
 .
 | 
Beta Was this translation helpful? Give feedback.
-
| No.
Of course you could make AsInt a def that takes implicit parameters to
create the extractor.… On Fri, Jun 11, 2021, 1:14 PM Erik Erlandson ***@***.***> wrote:
 would that allow the more complex curried parameter signatures, such in my
 original example at the top?
 def unapply(using Quotes)(u: quotes.reflect.TypeRepr): Option[Expr[NamedUnit]]
 —
 You are receiving this because you commented.
 Reply to this email directly, view it on GitHub
 <#12793 (reply in thread)>,
 or unsubscribe
 <https://github.com/notifications/unsubscribe-auth/AAAYAUFXNKXYBJNXCRQESCDTSI76PANCNFSM46Q74VEA>
 .
 | 
Beta Was this translation helpful? Give feedback.
-
| Here's yet a third idea: in any  // a is of type A, b is of type B
match a
    case foo(b) => ...the compiler simply admits any function  | 
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
pattern matching with
unapplyextractors requires the creation of a containing object, for example:I have been wondering if it would be more direct to replace
unapplywith an explicit name, but instead annotate it with something likedef extractor ..., like:Adding new keywords is not cost free but would reduce boilerplate
Beta Was this translation helpful? Give feedback.
All reactions