What is the purpose of a combined lens?

Looking through the Lens article on tea # 1 , I found a united lens. My implementation

 united :: Lens' a () united fv = const v <$> f () 

which is pretty much the same as the implementation in the Lens library .

Which leaves me completely puzzled, why do I need such a feature in the first place? Are there any uses for this lens?

+6
source share
1 answer

I have never seen or used this before. But I believe that this is useful in the same way that the id function (which returns its argument unmodified) or the Identity monad (which is a monad without "effects" exactly equivalent to not using the monad) are useful.

These and other similar concepts (including type () !) Are basically "do nothing" structures, so they seem useless when you look at them yourself. But they become useful when polymorphism is involved, giving you the option to "do nothing" to go to general operations.

+2
source

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


All Articles