TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

ADT through the looking glass – lenses, prisms and other optics in Scala

78 点作者 maddening超过 6 年前

6 条评论

cheriot超过 6 年前
I find the Monocle library does a good job of describing the motivation for type optics: <a href="http:&#x2F;&#x2F;julien-truffaut.github.io&#x2F;Monocle&#x2F;" rel="nofollow">http:&#x2F;&#x2F;julien-truffaut.github.io&#x2F;Monocle&#x2F;</a><p>Where I&#x27;ve used this in real code is via circe-optics (json parsing). An example: <a href="https:&#x2F;&#x2F;stackoverflow.com&#x2F;questions&#x2F;36724068&#x2F;how-to-parse-a-json-scala-without-case-classes" rel="nofollow">https:&#x2F;&#x2F;stackoverflow.com&#x2F;questions&#x2F;36724068&#x2F;how-to-parse-a-...</a>
lasagnaphil超过 6 年前
I mainly program in low-level imperative languages (mostly C&#x2F;C++), and occasionally dabbled in some functional languages (like Ocaml and Elm). But I don’t really understand why you would need such a convoluted system to get&#x2F;mutate some values in a data structure in Scala. Doesn’t Scala allow mutability throughout its language already (unlike Haskell)?
评论 #18750376 未加载
评论 #18751663 未加载
评论 #18750386 未加载
emarx超过 6 年前
Monocle also ships with the macro annotation <i>monocle.macros.Lenses</i> that cuts out even more of the boilerplate and works with intellij&#x27;s autocomplete<p><pre><code> import monocle.macros.Lenses @Lenses case class Foo(bar: Int) val x = Foo(1) assert(Foo.bar.get(x) == 1)</code></pre>
Cobord超过 6 年前
<a href="https:&#x2F;&#x2F;arxiv.org&#x2F;abs&#x2F;1809.00738" rel="nofollow">https:&#x2F;&#x2F;arxiv.org&#x2F;abs&#x2F;1809.00738</a> is really nice for general context. Plus can implement some of these generalizations from what is already here.
sk5t超过 6 年前
I like working in Scala quite a bit, but always wince at the &quot;instead of using threading primitives consider this 10x more exotic immutable approach&quot; lead-in. Does anyone here really work that way?
评论 #18750815 未加载
评论 #18750601 未加载
评论 #18750943 未加载
评论 #18750949 未加载
redfast00超过 6 年前
Takes a long time to parse because it the text has a lot of typos.
评论 #18750955 未加载