Use Scala Forwarders and Proxy Cases

The Scala collection library contains IterableForwarder , TraversableForwarder , SeqForwarder and proxy forwarders, for example IterableProxy , MapProxy , SeqProxy , SetProxy , TraversableProxy , etc. Freight forwarders and proxies both methods of collecting delegates to the base collection object. The main difference between the two is that forwarders do not divert calls that would create new collection objects of the same type.

When do I prefer one of these types over another? Why and when are freight forwarders useful? And if they are useful, why not MapForwarder and SetForwarder ?

I assume that proxies are most often used if you want to create a wrapper for a collection using additional methods or to pimp standard collections.

+6
source share
1 answer

I think this answer contains some Proxy context in general (and your assumption about wrapping and pimping would be correct).

As far as I can tell, Proxy subtypes are more end-user oriented. When using Proxy , the proxy object and the self object will be equal for all purposes. I think the main difference is actually. Do not use Proxy if this assumption is not fulfilled.

It seems that only forwarders use ListBuffer support and may be more appropriate if you need to deploy your own collection class built on top of the CanBuildFrom infrastructure. Therefore, I would say that it is more focused on librarians, where the library is based on the design of the collection 2.8.

+4
source

Source: https://habr.com/ru/post/886343/


All Articles