@@ -1103,7 +1103,7 @@ defmodule Module.Types.Descr do
1103
1103
[ { name , [ ] , arguments } | acc ]
1104
1104
else
1105
1105
negs
1106
- |> Enum . map ( fn { ty , lst } ->
1106
+ |> non_empty_map_or ( fn { ty , lst } ->
1107
1107
args =
1108
1108
if subtype? ( lst , @ empty_list ) do
1109
1109
[ to_quoted ( ty , opts ) ]
@@ -1113,7 +1113,6 @@ defmodule Module.Types.Descr do
1113
1113
1114
1114
{ name , [ ] , args }
1115
1115
end )
1116
- |> Enum . reduce ( & { :or , [ ] , [ & 2 , & 1 ] } )
1117
1116
|> Kernel . then (
1118
1117
& [
1119
1118
{ :and , [ ] , [ { name , [ ] , arguments } , { :not , [ ] , [ & 1 ] } ] }
@@ -1853,10 +1852,10 @@ defmodule Module.Types.Descr do
1853
1852
end
1854
1853
1855
1854
# Use heuristics to normalize a map dnf for pretty printing.
1856
- defp map_normalize ( dnf ) do
1857
- dnf
1858
- |> Enum . reject ( & map_empty? ( [ & 1 ] ) )
1859
- |> Enum . map ( fn { tag , fields , negs } ->
1855
+ defp map_normalize ( dnfs ) do
1856
+ for dnf <- dnfs , not map_empty? ( [ dnf ] ) do
1857
+ { tag , fields , negs } = dnf
1858
+
1860
1859
{ fields , negs } =
1861
1860
Enum . reduce ( negs , { fields , [ ] } , fn neg = { neg_tag , neg_fields } , { acc_fields , acc_negs } ->
1862
1861
if map_empty_negation? ( tag , acc_fields , neg ) do
@@ -1874,7 +1873,7 @@ defmodule Module.Types.Descr do
1874
1873
end )
1875
1874
1876
1875
{ tag , fields , negs }
1877
- end )
1876
+ end
1878
1877
|> map_fusion ( )
1879
1878
end
1880
1879
@@ -1955,8 +1954,7 @@ defmodule Module.Types.Descr do
1955
1954
1956
1955
_ ->
1957
1956
negative_maps
1958
- |> Enum . map ( & map_literal_to_quoted ( & 1 , opts ) )
1959
- |> Enum . reduce ( & { :or , [ ] , [ & 2 , & 1 ] } )
1957
+ |> non_empty_map_or ( & map_literal_to_quoted ( & 1 , opts ) )
1960
1958
|> Kernel . then (
1961
1959
& { :and , [ ] , [ map_literal_to_quoted ( { tag , positive_map } , opts ) , { :not , [ ] , [ & 1 ] } ] }
1962
1960
)
@@ -2309,8 +2307,7 @@ defmodule Module.Types.Descr do
2309
2307
2310
2308
_ ->
2311
2309
negative_tuples
2312
- |> Enum . map ( & tuple_literal_to_quoted ( & 1 , opts ) )
2313
- |> Enum . reduce ( & { :or , [ ] , [ & 2 , & 1 ] } )
2310
+ |> non_empty_map_or ( & tuple_literal_to_quoted ( & 1 , opts ) )
2314
2311
|> Kernel . then (
2315
2312
& { :and , [ ] , [ tuple_literal_to_quoted ( { tag , positive_tuple } , opts ) , { :not , [ ] , [ & 1 ] } ] }
2316
2313
)
@@ -2575,8 +2572,9 @@ defmodule Module.Types.Descr do
2575
2572
none ( )
2576
2573
else
2577
2574
n .. ( m - 1 ) // 1
2578
- |> Enum . map ( & tuple_values ( :closed , tuple_fill ( elements , & 1 ) , negs ) )
2579
- |> Enum . reduce ( none ( ) , & union / 2 )
2575
+ |> Enum . reduce ( none ( ) , fn i , acc ->
2576
+ tuple_values ( :closed , tuple_fill ( elements , i ) , negs ) |> union ( acc )
2577
+ end )
2580
2578
|> union (
2581
2579
if neg_tag == :open do
2582
2580
none ( )
@@ -2971,4 +2969,8 @@ defmodule Module.Types.Descr do
2971
2969
end
2972
2970
2973
2971
defp iterator_non_disjoint_intersection? ( :none , _map ) , do: false
2972
+
2973
+ defp non_empty_map_or ( [ head | tail ] , fun ) do
2974
+ Enum . reduce ( tail , fun . ( head ) , & { :or , [ ] , [ & 2 , fun . ( & 1 ) ] } )
2975
+ end
2974
2976
end
0 commit comments