Skip to content

Commit

Permalink
No_Wrap is an uniquely constructible builtin
Browse files Browse the repository at this point in the history
  • Loading branch information
Akirathan committed Nov 4, 2024
1 parent ab27a4d commit 5b96444
Show file tree
Hide file tree
Showing 23 changed files with 89 additions and 84 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ type Statistic
compute_bulk : Vector -> Vector Statistic -> Vector Any
compute_bulk data statistics:Vector=[Statistic.Count, Statistic.Sum] =
resolved_stats = statistics.map (r-> r:Statistic)
moment_order = resolved_stats.map on_problems=No_Wrap .order
moment_order = resolved_stats.map on_problems=No_Wrap.Value .order
has_min_max = resolved_stats.any (s-> s == Statistic.Minimum || s == Statistic.Maximum)
has_product = resolved_stats.any (s-> s == Statistic.Product)
max_moment_order = moment_order.filter (v-> v != Nothing) . fold 0 .max
Expand All @@ -202,7 +202,7 @@ type Statistic
Error.throw (Illegal_Argument.Error ("Can only compute " + stat.to_text + " on numerical data sets."))

if max_moment_order > 0 && counter.moments.is_nothing then report_error resolved_stats else
resolved_stats.map on_problems=No_Wrap statistic-> case statistic of
resolved_stats.map on_problems=No_Wrap.Value statistic-> case statistic of
Statistic.Covariance series -> check_if_empty counter.count <| calculate_correlation_statistics data series . covariance
Statistic.Pearson series -> check_if_empty counter.count <| calculate_correlation_statistics data series . pearsonCorrelation
Statistic.R_Squared series -> check_if_empty counter.count <| calculate_correlation_statistics data series . rSquared
Expand All @@ -229,7 +229,7 @@ type Statistic
running_bulk data statistics=[Statistic.Count, Statistic.Sum] =
resolved_stats = statistics.map (r-> r:Statistic)
check_running_support resolved_stats <|
moment_order = resolved_stats.map on_problems=No_Wrap .order
moment_order = resolved_stats.map on_problems=No_Wrap.Value .order
has_min_max = resolved_stats.any (s-> s == Statistic.Minimum || s == Statistic.Maximum)
has_product = resolved_stats.any (s-> s == Statistic.Product)
max_moment_order = moment_order.filter (v-> v != Nothing) . fold 0 .max
Expand All @@ -241,7 +241,7 @@ type Statistic
data.fold counter current->value->
result = compute_fold current value

row = Panic.rethrow_wrapped_if_error <| resolved_stats.map on_problems=No_Wrap s-> case s of
row = Panic.rethrow_wrapped_if_error <| resolved_stats.map on_problems=No_Wrap.Value s-> case s of
Statistic.Maximum -> if result.count == 0 then Nothing else result.maximum
Statistic.Minimum -> if result.count == 0 then Nothing else result.minimum
_ -> result.compute s
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1550,6 +1550,7 @@ type Map_Error
Indicates that a method should not wrap thrown errors in `Map_Error`.
@Builtin_Type
type No_Wrap
Value

## PRIVATE
Wrapped_Error.from (that : Map_Error) = Wrapped_Error.Value that that.inner_error
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ type HTTP
boundary = body_publisher_and_boundary.second
boundary_header_list = if boundary.is_nothing then [] else [Header.multipart_form_data boundary]
all_headers = headers + boundary_header_list
mapped_headers = all_headers.map on_problems=No_Wrap .to_java_pair
mapped_headers = all_headers.map on_problems=No_Wrap.Value .to_java_pair

response = Response.Value (EnsoSecretHelper.makeRequest self.internal_http_client builder req.uri.to_java_representation mapped_headers)
if error_on_failure_code.not || response.code.is_success then response else
Expand Down Expand Up @@ -186,7 +186,7 @@ type HTTP
## PRIVATE
parse_headers : Vector (Header | Pair Text Text) -> Vector Header
parse_headers headers =
headers . map on_problems=No_Wrap h-> case h of
headers . map on_problems=No_Wrap.Value h-> case h of
_ : Vector -> Header.new (h.at 0) (h.at 1)
_ : Pair -> Header.new (h.at 0) (h.at 1)
_ : Function -> h:Header
Expand Down
2 changes: 1 addition & 1 deletion distribution/lib/Standard/Base/0.0.0-dev/src/Warning.enso
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ set_array value warnings = @Builtin_Method "Warning.set_array"
map_attached_warnings_helper : (Any -> Maybe Any) -> Any -> Integer -> Any
map_attached_warnings_helper mapper value frames_to_drop =
warnings = Warning.get_all value
mapped_warnings = warnings.map on_problems=No_Wrap warning->
mapped_warnings = warnings.map on_problems=No_Wrap.Value warning->
case mapper warning.value of
Maybe.Some new_payload ->
self_call_name = "Warning.map_attached_warnings_helper"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ run_transaction_with_tables connection (tables : Vector Transactional_Table_Desc
## PRIVATE
private create_tables_inside_transaction connection (tables : Vector Transactional_Table_Description) (callback : Vector DB_Table -> Any) -> Any =
connection.jdbc_connection.run_within_transaction <|
created = tables.map on_problems=No_Wrap t-> t.create connection
created = tables.map on_problems=No_Wrap.Value t-> t.create connection
created.if_not_error <|
result = callback created

Expand All @@ -89,7 +89,7 @@ private create_tables_outside_transaction connection (tables : Vector Transactio
Panic.throw caught_panic

Panic.catch Any handler=handle_panic <|
created = tables.map on_problems=No_Wrap t->
created = tables.map on_problems=No_Wrap.Value t->
table = t.create connection
# We only register a table for cleanup if it was successfully created.
table.if_not_error <|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,8 @@ type Context
rewrite_internal_column column =
Internal_Column.Value column.name column.sql_type_reference (SQL_Expression.Column alias column.name)

new_columns = column_lists.map on_problems=No_Wrap columns->
columns.map on_problems=No_Wrap rewrite_internal_column
new_columns = column_lists.map on_problems=No_Wrap.Value columns->
columns.map on_problems=No_Wrap.Value rewrite_internal_column

encapsulated_columns = column_lists.flat_map columns->
columns.map column-> [column.name, column.expression]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ check_target_table_for_update target_table ~action = case target_table of
resolve_primary_key structure primary_key = case primary_key of
Nothing -> Nothing
_ : Vector -> if primary_key.is_empty then Nothing else
validated = primary_key.map on_problems=No_Wrap key->
validated = primary_key.map on_problems=No_Wrap.Value key->
if key.is_a Text then key else
Error.throw (Illegal_Argument.Error ("Primary key must be a vector of column names, instead got a " + (Meta.type_of key . to_display_text)))
validated.if_not_error <|
Expand Down Expand Up @@ -74,6 +74,6 @@ check_update_arguments_structure_match source_table target_table key_columns upd
if missing_target_key_columns.not_empty then Error.throw (Missing_Input_Columns.Error missing_target_key_columns.to_vector "the target table") else
if (update_action != Update_Action.Insert) && key_columns.is_empty then Error.throw (Illegal_Argument.Error "For the `update_action = "+update_action.to_text+"`, the `key_columns` must be specified to define how to match the records.") else
# Verify type matching
problems = source_table.columns.flat_map on_problems=No_Wrap check_source_column
problems = source_table.columns.flat_map on_problems=No_Wrap.Value check_source_column
problems.if_not_error <|
on_problems.attach_problems_before problems action
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ make_batched_insert_template connection table_name column_names =
prepare_create_table_statement : Connection -> Text -> Vector Column_Description -> Vector Text -> Boolean -> Problem_Behavior -> SQL_Statement
prepare_create_table_statement connection table_name columns primary_key temporary on_problems:Problem_Behavior =
type_mapping = connection.dialect.get_type_mapping
column_descriptors = columns.map on_problems=No_Wrap def->
column_descriptors = columns.map on_problems=No_Wrap.Value def->
sql_type = type_mapping.value_type_to_sql def.value_type on_problems
sql_type_text = type_mapping.sql_type_to_text sql_type
Create_Column_Descriptor.Value def.name sql_type_text def.constraints
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ take_drop_helper take_drop table selector:(Index_Sub_Range | Range | Integer) =
row_column_name = table.make_temp_column_name
table_with_row_number = table.add_row_number name=row_column_name from=0

subqueries = ranges.map on_problems=No_Wrap range->
subqueries = ranges.map on_problems=No_Wrap.Value range->
generate_subquery table_with_row_number row_column_name range
combined = subqueries.reduce (a-> b-> a.union b)
combined.remove_columns row_column_name
Expand Down
4 changes: 2 additions & 2 deletions distribution/lib/Standard/Table/0.0.0-dev/src/Column.enso
Original file line number Diff line number Diff line change
Expand Up @@ -2101,7 +2101,7 @@ type Column
map : (Any -> Any) -> Boolean -> Value_Type | Auto -> Column ! Invalid_Value_Type
map self function skip_nothing=True expected_value_type=Auto =
new_fn = if skip_nothing then (x-> if x.is_nothing then Nothing else function x) else function
new_st = self.to_vector.map on_problems=No_Wrap new_fn
new_st = self.to_vector.map on_problems=No_Wrap.Value new_fn
Column.from_vector self.name new_st value_type=expected_value_type

## ALIAS combine, join by row position, merge
Expand Down Expand Up @@ -2149,7 +2149,7 @@ type Column
function x y
False -> function
new_name = naming_helper.binary_operation_name "x" self that
vec = self.to_vector.zip on_problems=No_Wrap that.to_vector new_fn
vec = self.to_vector.zip on_problems=No_Wrap.Value that.to_vector new_fn
Column.from_vector new_name vec value_type=expected_value_type

## GROUP Standard.Base.Metadata
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ type Data_Formatter
vector = case formats of
v : Vector -> v
singleton -> [singleton]
converted = vector.map on_problems=No_Wrap elem->
converted = vector.map on_problems=No_Wrap.Value elem->
## Ensure the element is a `Date_Time_Formatter` or is converted to it.
We need to convert _each_ element - we cannot perform a 'bulk' conversion like `vector : Vector Date_Time_Formatter` because of erasure.
checked = elem : Date_Time_Formatter
Expand Down Expand Up @@ -216,17 +216,17 @@ type Data_Formatter
## PRIVATE
make_date_parser self = self.wrap_base_parser <|
Panic.catch JException handler=(caught_panic-> Error.throw (Illegal_Argument.Error caught_panic.payload.getMessage)) <|
DateParser.new (self.date_formats.map on_problems=No_Wrap .get_java_formatter_for_parsing)
DateParser.new (self.date_formats.map on_problems=No_Wrap.Value .get_java_formatter_for_parsing)

## PRIVATE
make_date_time_parser self = self.wrap_base_parser <|
Panic.catch JException handler=(caught_panic-> Error.throw (Illegal_Argument.Error caught_panic.payload.getMessage)) <|
DateTimeParser.new (self.datetime_formats.map on_problems=No_Wrap .get_java_formatter_for_parsing)
DateTimeParser.new (self.datetime_formats.map on_problems=No_Wrap.Value .get_java_formatter_for_parsing)

## PRIVATE
make_time_of_day_parser self = self.wrap_base_parser <|
Panic.catch JException handler=(caught_panic-> Error.throw (Illegal_Argument.Error caught_panic.payload.getMessage)) <|
TimeOfDayParser.new (self.time_formats.map on_problems=No_Wrap .get_java_formatter_for_parsing)
TimeOfDayParser.new (self.time_formats.map on_problems=No_Wrap.Value .get_java_formatter_for_parsing)

## PRIVATE
make_identity_parser self = self.wrap_base_parser IdentityParser.new
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ prepare_aggregate_columns naming_helper group_by aggregates table error_on_missi
assert (resolved_keys.contains Nothing . not)
problem_builder = Problem_Builder.new error_on_missing_columns=error_on_missing_columns
columns = if old_style then group_by else keys+aggregates
valid_resolved_aggregate_columns = columns.map on_problems=No_Wrap (resolve_aggregate table problem_builder) . filter x-> x.is_nothing.not
valid_resolved_aggregate_columns = columns.map on_problems=No_Wrap.Value (resolve_aggregate table problem_builder) . filter x-> x.is_nothing.not

# Grouping Key
key_columns = resolved_keys.map .column
Expand All @@ -80,7 +80,7 @@ prepare_aggregate_columns naming_helper group_by aggregates table error_on_missi
The second pass resolves the default names, ensuring that they do not
clash with the user-specified names (ensuring that user-specified names
take precedence).
pass_1 = valid_resolved_aggregate_columns.map on_problems=No_Wrap c-> if c.as == "" then "" else
pass_1 = valid_resolved_aggregate_columns.map on_problems=No_Wrap.Value c-> if c.as == "" then "" else
# Verify if the user-provided name is valid and if not, throw an error.
naming_helper.ensure_name_is_valid c.as <|
unique.make_unique c.as
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ unpack_problem_summary problem_summary =
## TODO [RW, GT] In the next iterations we will want to remove
`translate_problem` in favour of constructing Enso problem instances
directly in Java code. To do so, we will need https://github.com/enso-org/enso/issues/7797
parsed = problems_array . map on_problems=No_Wrap translate_problem
parsed = problems_array . map on_problems=No_Wrap.Value translate_problem
if count == parsed.length then parsed else
parsed + [Additional_Warnings.Error (count - parsed.length)]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ type Join_Condition_Resolver
is_nothing column = case column of
Nothing -> True
_ -> False
conditions_vector = Vector.unify_vector_or_element conditions . map on_problems=No_Wrap condition-> (condition:Join_Condition)
conditions_vector = Vector.unify_vector_or_element conditions . map on_problems=No_Wrap.Value condition-> (condition:Join_Condition)
handle_equals left_selector right_selector =
left = resolve_left left_selector
right = resolve_right right_selector
Expand All @@ -52,7 +52,7 @@ type Join_Condition_Resolver
if left.name == right.name then
redundant_names.append right.name
self.make_equals problem_builder left right
converted = conditions_vector.map on_problems=No_Wrap condition-> case condition of
converted = conditions_vector.map on_problems=No_Wrap.Value condition-> case condition of
Join_Condition.Equals left_selector right_selector ->
right_resovled = if right_selector == "" then left_selector else right_selector
handle_equals left_selector right_resovled
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ prepare_columns_for_lookup base_table lookup_table key_columns_selector add_new_
problems_to_add = Builder.new
key_columns.if_not_error <| lookup_table_key_columns.if_not_error <|
key_set = Hashset.from_vector key_columns
my_updated_columns = base_table.columns.map on_problems=No_Wrap base_column->
my_updated_columns = base_table.columns.map on_problems=No_Wrap.Value base_column->
base_column_name = base_column.name
is_key = key_set.contains base_column_name
case is_key of
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -582,5 +582,5 @@ replace_columns_with_transformed_columns : Table -> Text | Integer | Regex | Vec
replace_columns_with_transformed_columns table selectors transformer error_on_missing_columns=True on_problems:Problem_Behavior=..Report_Warning =
internal_columns = table.columns_helper.select_columns selectors Case_Sensitivity.Default reorder=False error_on_missing_columns=error_on_missing_columns on_problems=on_problems
columns = internal_columns.map table.columns_helper.make_column
new_columns = columns.map on_problems=No_Wrap transformer
new_columns = columns.map on_problems=No_Wrap.Value transformer
replace_columns_with_columns table columns new_columns
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,6 @@ check_is_in_values operation_name values =
Error.throw (Illegal_Argument.Error message)
_ -> v
case values of
_ : Vector -> values.map on_problems=No_Wrap check_value
_ : Array -> values.map on_problems=No_Wrap check_value
_ : Vector -> values.map on_problems=No_Wrap.Value check_value
_ : Array -> values.map on_problems=No_Wrap.Value check_value
_ -> check_value values
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ check_binary_boolean_op arg1 arg2 ~action =
- action: the action to run if the arguments are compatible.
check_multi_argument_comparable_op column arg_or_args ~action =
args = Vector.unify_vector_or_element arg_or_args
checked = args.map on_problems=No_Wrap arg->
checked = args.map on_problems=No_Wrap.Value arg->
Value_Type.expect_comparable column arg <|
True
checked.if_not_error <|
Expand Down
Loading

0 comments on commit 5b96444

Please sign in to comment.