-
-
Notifications
You must be signed in to change notification settings - Fork 8
Various fixes #86
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
base: main
Are you sure you want to change the base?
Various fixes #86
Changes from all commits
92b1ad5
76316c1
7b45631
2ec119d
4a5dbf4
b42f5c1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -73,9 +73,9 @@ defmodule Drops.Type.DSL do | |
| """ | ||
| @doc since: "0.1.0" | ||
|
|
||
| @spec type({atom(), []}) :: type() | ||
| @spec type({atom(), list()}) :: type() | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The Elixir docs say that a typespec of |
||
| @spec type(list: atom()) :: type() | ||
| @spec type(list: []) :: type() | ||
| @spec type(list: list()) :: type() | ||
| @spec type([atom()]) :: [type()] | ||
| @spec type(atom()) :: type() | ||
|
|
||
|
|
@@ -113,8 +113,8 @@ defmodule Drops.Type.DSL do | |
| """ | ||
| @doc since: "0.1.0" | ||
|
|
||
| @spec type(atom(), []) :: type() | ||
| @spec type({:cast, {atom(), []}}, type()) :: type() | ||
| @spec type(atom(), list()) :: type() | ||
| @spec type({:cast, {atom(), list()}}, type()) :: type() | ||
|
|
||
| def type([type | rest], predicates) do | ||
| union([type | rest], predicates) | ||
|
|
@@ -251,7 +251,7 @@ defmodule Drops.Type.DSL do | |
| """ | ||
| @doc since: "0.1.0" | ||
|
|
||
| @spec maybe(atom(), []) :: type() | ||
| @spec maybe(atom(), list()) :: type() | ||
|
|
||
| def maybe(type, predicates \\ []) do | ||
| type([nil, {type, predicates}]) | ||
|
|
@@ -289,7 +289,7 @@ defmodule Drops.Type.DSL do | |
| @doc since: "0.1.0" | ||
|
|
||
| @spec string(atom()) :: type() | ||
| @spec string([]) :: type() | ||
| @spec string(list()) :: type() | ||
|
|
||
| def string(predicate) when is_atom(predicate) do | ||
| string([predicate]) | ||
|
|
@@ -335,7 +335,7 @@ defmodule Drops.Type.DSL do | |
| @doc since: "0.1.0" | ||
|
|
||
| @spec integer(atom()) :: type() | ||
| @spec integer([]) :: type() | ||
| @spec integer(list()) :: type() | ||
|
|
||
| def integer(predicate) when is_atom(predicate) do | ||
| integer([predicate]) | ||
|
|
@@ -377,7 +377,7 @@ defmodule Drops.Type.DSL do | |
| """ | ||
| @doc since: "0.1.0" | ||
|
|
||
| @spec float([]) :: type() | ||
| @spec float(list()) :: type() | ||
|
|
||
| def float(predicates) when is_list(predicates) do | ||
| type(:float, predicates) | ||
|
|
@@ -460,7 +460,7 @@ defmodule Drops.Type.DSL do | |
| @doc since: "0.1.0" | ||
|
|
||
| @spec map(atom()) :: type() | ||
| @spec map([]) :: type() | ||
| @spec map(list()) :: type() | ||
|
|
||
| def map(predicate) when is_atom(predicate) do | ||
| map([predicate]) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -101,9 +101,27 @@ defmodule Drops.Types.Union do | |
| }) | ||
| end | ||
|
|
||
| defp constrain(%Drops.Types.Cast{input_type: input_type} = type, predicates) do | ||
| Map.merge(type, %{ | ||
| input_type: constrain(input_type, predicates) | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wasn't sure if the constraint should be applied to the input type, the output type, or both. |
||
| }) | ||
| end | ||
|
|
||
| defp constrain(%Drops.Types.Union{left: left, right: right} = type, predicates) do | ||
| Map.merge(type, %{ | ||
| left: constrain(left, predicates), | ||
| right: constrain(right, predicates) | ||
| }) | ||
| end | ||
|
|
||
| defp constrain(type, predicates) do | ||
| constraints = | ||
| case type.constraints do | ||
| {:and, constraints} -> {:and, constraints ++ infer_constraints(predicates)} | ||
| constraints when is_list(constraints) -> constraints ++ infer_constraints(predicates) | ||
| end | ||
| Map.merge(type, %{ | ||
| constraints: type.constraints ++ infer_constraints(predicates) | ||
| constraints: constraints | ||
| }) | ||
| end | ||
| end | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I made the minimal changes to make this work. But it looks like
{:and, constraints}gets treated the same as justconstraints, so I wonder if we can just get rid of{:and, ...}everywhere.