TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

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

78 pointsby maddeningover 6 years ago

6 comments

cheriotover 6 years ago
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>
lasagnaphilover 6 years ago
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 未加载
emarxover 6 years ago
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>
Cobordover 6 years ago
<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.
sk5tover 6 years ago
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 未加载
redfast00over 6 years ago
Takes a long time to parse because it the text has a lot of typos.
评论 #18750955 未加载