Giter VIP home page Giter VIP logo

Comments (4)

obrok avatar obrok commented on June 5, 2024

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.

obrok avatar obrok commented on June 5, 2024

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.

binarytemple avatar binarytemple commented on June 5, 2024

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.

obrok avatar obrok commented on June 5, 2024

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 photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.