功能性镜片
有人可以向我解释一下功能性镜片吗?对于谷歌来说,这是一个令人惊讶的困难主题,而且我还没有取得任何进展。我所知道的是它们提供了与 OO 类似的获取/设置功能。
Could someone explain functional lenses to me? It's a surprisingly difficult subject to google for and I haven't made any progress. All I know is that they provide similar get/set functionality than in OO.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
透镜由两个函数组成,一个 getter 和一个 setter:
例如,我们可能有一对透镜的第一部分和第二部分:
透镜的真正便利之处在于它们组成:
并且它们会机械地转换为
State< /代码> 转换:
A lens consists of two functions, a getter and a setter:
For example, we might have lenses for the first and second parts of a pair:
The real convenience of lenses is that they compose:
And they mechanically convert to
State
transitions:请参阅问题的答案镜头、fclabels、数据-accessor - 哪个结构访问和突变库更好 - 它对镜头有非常清晰的解释。
此外,还有数据的文档。镜头和fclabel 库提供了一些很好的使用示例。
See the answer to question lenses, fclabels, data-accessor - which library for structure access and mutation is better - it has a very clear explanation on lenses.
Also, the documentation for the Data.Lenses and fclabel libraries give some good examples of them being used.