Member Patterns -- the bikeshed
Attila Kelemen
attila.kelemen85 at gmail.com
Mon Apr 1 16:31:14 UTC 2024
>
> Lambdas. A SAM interface is one with a single abstract method, and we
> extract the function shape and use it as a target type for lambdas.
> Similarly, a SAP interface is one with a single abstract pattern. We can
> play the same game, except the shape is (match candidate) -> { pattern body
> that binds declared bindings }. This allows APIs to be extend with
> patterns, such as a `match` method in streams:
>
> objects.stream().match(e -> e instanceof String s)....
>
> where Stream::match takes a SAP interface with a single binding, such as:
>
> interface Matchy<T, U> {
> pattern(T that) p(U u);
> }
> ...
> // in Stream
> <U> Stream<U> match(Matchy<T,U> m);
>
I see, thanks. What I was missing is that I thought a "pattern" method
cannot exist without its pair. And that explains why wasn't the short
"inverse" syntax chosen: Because the fact that the "pattern" method has the
same name / types is just a coincidence from the point of view of the
compiler (hopefully I'm not misunderstanding something again).
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/amber-spec-observers/attachments/20240401/b24bdb7d/attachment.htm>
More information about the amber-spec-observers
mailing list