Comments (4)
That's just because Map.get(nil, :a)
is nil
, so you can indeed recurse infinitely deep into a nil
like that. I wrote most of this library a while back, can't remember if that's how it always was in Elixir, or if it changed... It's not quite clear to me if a proper fix exists that doesn't break something else. For example, we could make it so that Lens.key(:a)
gives no results when applied to a nil
, but that breaks the simple relationship that Lens.to_list(Lens.key(k), m) == [m[k]]
.
from lens.
Ah! Scratch that, I forgot how my own library works! There's key?
for just this purpose. You can do:
Lens.recur(Lens.key?(:a)) |> Lens.to_list(%{a: %{a: %{b: :c}}})
# => [%{b: :c}, %{a: %{b: :c}}]
which, I think, is what you wanted.
from lens.
Thanks @obrok - that gets me over that hump, maybe for beginners the infinite recursion might be a bit non obvious, I've been having great fun playing with your library so thanks for creating it and thanks for the guidance 🙇
from lens.
Thank you for your kind words! I'd say Lens.recur
is a little bit more advanced (although very useful indeed) in that it's difficult to debug when things go wrong. If you'd like to make a PR adding a FAQ section to the README describing this problem and the solution, I'd be happy to merge that.
from lens.
Related Issues (7)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from lens.