-
Notifications
You must be signed in to change notification settings - Fork 5
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
Destructure Structures #2
Comments
This needs to be re-opened (I don't have permission) for three reasons:
defmodule Foo do
defstruct bar: 0
import Destructure
def new(bar), do: d%Foo{bar}
end
assert %Foo{bar: 1} == Foo.new(1) Specifically,
defmodule Baz
defstruct bar: 0
end
assert d(%Foo{bar}) = %Baz{bar: 1} This assert should fail. It doesn't. Meaning that a literal there doesn't provide (runtime) type safety.
d(%x{}) = %Foo{}
assert x == Foo Currently this returns
|
2 and 3 are valid points, so I'm reopening. However, your first point is not. This code: def new(bar), do: d%{bar} Compiles down to: def new(bar), do: %{bar: bar} Nowhere in either version is the struct specified, so it isn't surprising that the |
Point 1 is valid. I just forgot to put the For an iex example (using
|
I see your point. I have to admit, my implementation is rather clumsy. I'll try to submit the patch soon. |
This fails to compile. I would like it to compile, and have
bar
in scope intake_foo/1
.The text was updated successfully, but these errors were encountered: