Code Monkey home page Code Monkey logo

Comments (8)

boxxxie avatar boxxxie commented on June 3, 2024

Lens.satisfy(&(&1)) is what i used
this may be worthy of adding to the library as an idiom
or do you know of a different way to do this that is better/idiomatic?

from lens.

obrok avatar obrok commented on June 3, 2024

Not quite sure what you mean - could you post an example?

from lens.

obrok avatar obrok commented on June 3, 2024

Do you mean you want something like:

iex> Lens.to_list(lens, %{a: 1})
[1]
iex> Lens.to_list(lens, %{})
[]

from lens.

boxxxie avatar boxxxie commented on June 3, 2024

yeah, so i had a parent node that is sometimes nil, and i focus on it's children.
so similar to what you posted

from lens.

boxxxie avatar boxxxie commented on June 3, 2024

example
:secondary is sometime nil

    people_lens =
      Lens.multiple([
        Lens.key(:primary),
        Lens.key(:secondary)])
      |> Lens.satisfy(exists) #existence check

    age_lens =
      people_lens
      |> Lens.both(Lens.key(:children) |> Lens.all)
      |> Lens.key(:age)

from lens.

obrok avatar obrok commented on June 3, 2024

Yeah, I think Lens.satisfy(&(&1)) is fine for this case... Not sure if there should be a separate function for this if such an easy solution exists.

from lens.

boxxxie avatar boxxxie commented on June 3, 2024

I think it may not be obvious.
may need more examples of how to use the library.

from lens.

obrok avatar obrok commented on June 3, 2024

If you think you have a way to make this obvious in the API, please make a PR, closing for now.

from lens.

Related Issues (6)

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.