Coder Social home page Coder Social logo

focus's People

Contributors

alexdeleon avatar pmeinhardt avatar smpoulsen avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

focus's Issues

safe_view throwing an error when index doesn't exists

la = Lens.make_lens("a")
lb = Lens.make_lens("b")
i0 = Lens.idx(0)

This works
la ~> i0 ~> lb |> Lens.safe_view(%{"a" => [%{"b" => 3}]})

This crashes
la ~> i0 ~> lb |> Lens.safe_view(%{"a" => []})

** (FunctionClauseError) no function clause matching in Keyword.get/3
(elixir) lib/keyword.ex:150: Keyword.get([], 0, nil)
lib/focus.ex:147: anonymous fn/3 in Focus.compose/2

Shouldn't "safe_view" be safe and not crash when something is missing?

Readme Link broken

Hi !
just noticed that the second link in the References section (Lenses in Functional Programming) is broken

Is it possible to target multiple / all items in a list in a generic way?

Hey, thanks for focus, this is quite superb way to deal with large payloads!

I have one question and I could not answer it after looking through Readme / codebase / tests.

Given the following datastructure:

payload = %{
items: [
  %{id: 1, price: 12.99}, 
  %{id: 2, price: 34.60}, 
  %{id: 3, price: 99.28}, 
]
}

how can one

  • convert all ids to strings?
  • collect all prices?
  • round up prices?
  • etc... ?

Does focus support targeting all items in a list in a generic way, means without explicit index option?

Thanks and have a nice day!
Roman

Consider making structure the first argument to get/set/etc... functions

The original intention with making the lens the first argument was to support composing a long chain of lenses and piping into Focus.view/2, Focus.set/3, Focus.over/3 etc….

There is obvious value in making the data structure the first argument, as focus could then slot directly into pipeline operations.

Lens.safe_view crashes after 3rd composed lens when there is index

import Focus
data = %{a: []}
a = Lens.make_lens(:a)
b = Lens.make_lens(:b)
c = Lens.make_lens(:c)
d = Lens.make_lens(:d)
i0 = Lens.idx(0)

This works fine:
a ~> b ~> c ~> d |> Lens.safe_view(data)
{:error, {:lens, :bad_path}}

This crashes
a ~> i0 ~> b ~> c |> Lens.safe_view(data)
** (ArithmeticError) bad argument in arithmetic expression
Lensable.Tuple.getter/2
lib/lens/lens.ex:227: Lens.safe_view/2

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.