Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

safe_view throwing an error when index doesn't exists #16

Closed
adleroliveira opened this issue Jul 12, 2017 · 1 comment
Closed

safe_view throwing an error when index doesn't exists #16

adleroliveira opened this issue Jul 12, 2017 · 1 comment

Comments

@adleroliveira
Copy link

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?

@smpoulsen
Copy link
Owner

smpoulsen commented Jul 12, 2017 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants