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

The in? predicate raises an exception for single-element lists. #55

Closed
ndan opened this issue Jul 11, 2024 · 1 comment · Fixed by #58
Closed

The in? predicate raises an exception for single-element lists. #55

ndan opened this issue Jul 11, 2024 · 1 comment · Fixed by #58
Assignees
Milestone

Comments

@ndan
Copy link

ndan commented Jul 11, 2024

The in? predicate raises an exception when the list contains a single element.

defmodule Contract do
  use Drops.Contract

  schema do
    %{
      optional(:side) => string(in?: ["salad"]),
      optional(:meat) => string(in?: ["chicken", "beef"])
    }
  end
end

Contract.conform(%{meat: "chicken"}) # => {:ok, %{meat: "chicken"}}

Contract.conform(%{side: "salad"})

# ** (FunctionClauseError) no function clause matching in Drops.Predicates.in?/2
# 
#     The following arguments were given to Drops.Predicates.in?/2:
# 
#         # 1
#         "salad"
# 
#         # 2
#         "salad"
# 
#     Attempted function clauses (showing 1 out of 1):
# 
#         def in?(list, input) when is_list(list)
# 
#     (drops 0.2.0) lib/drops/predicates.ex:377: Drops.Predicates.in?/2
#     (drops 0.2.0) lib/drops/predicates/helpers.ex:22: Drops.Predicates.Helpers.apply_predicate/2
#     (elixir 1.17.1) lib/enum.ex:2531: Enum."-reduce/3-lists^foldl/2-0-"/3
#     (drops 0.2.0) lib/drops/types/map/key.ex:15: Drops.Types.Map.Key.validate/2
#     (elixir 1.17.1) lib/enum.ex:1703: Enum."-map/2-lists^map/1-1-"/2
#     (elixir 1.17.1) lib/enum.ex:1703: Enum."-map/2-lists^map/1-1-"/2
#     (drops 0.2.0) lib/drops/types/map.ex:63: Drops.Types.Map.Validator.validate/2
#     iex:6: Contract.conform/3
@solnic
Copy link
Owner

solnic commented Jul 19, 2024

Ah thanks for reporting this. I'll fix it in the next release sometime next week :)

@solnic solnic added this to the v0.2.1 milestone Jul 19, 2024
@solnic solnic self-assigned this Jul 26, 2024
solnic added a commit that referenced this issue Jul 26, 2024
@solnic solnic linked a pull request Jul 26, 2024 that will close this issue
@solnic solnic closed this as completed in 4aebadc Jul 26, 2024
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

Successfully merging a pull request may close this issue.

2 participants