Skip to content

Commit

Permalink
if_nothing
Browse files Browse the repository at this point in the history
Remove Group_By_Key
  • Loading branch information
jdunkerley committed May 10, 2022
1 parent bae2ec8 commit 23406f0
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 61 deletions.
9 changes: 9 additions & 0 deletions distribution/lib/Standard/Base/0.0.0-dev/src/Data/Any.enso
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,15 @@ type Any
is_nothing : Boolean
is_nothing = False

## If this is Nothing then returns `function`.

> Example
If the value "Hello" is nothing return "".

"Hello".if_nothing ""
if_nothing : Any
if_nothing ~_ = this

## Executes the provided handler on an error, or returns a non-error value
unchanged.

Expand Down
4 changes: 2 additions & 2 deletions distribution/lib/Standard/Base/0.0.0-dev/src/Data/Locale.enso
Original file line number Diff line number Diff line change
Expand Up @@ -249,8 +249,8 @@ us = here.from_language_tag "en-US"
example_new = Locale.new "en" "GB" "UTF-8"
new : Text -> Text | Nothing -> Text | Nothing -> Locale
new language country=Nothing variant=Nothing =
country_text = if country.is_nothing then "" else country
variant_text = if variant.is_nothing then "" else variant
country_text = country.if_nothing ""
variant_text = variant.if_nothing ""
java_locale = JavaLocale.new language country_text variant_text
here.from_java java_locale

Expand Down
17 changes: 12 additions & 5 deletions distribution/lib/Standard/Base/0.0.0-dev/src/Nothing.enso
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from Standard.Base import Boolean, True

type Nothing
## The type that has only a singleton value.
## The type that has only a singleton value. Nothing in Enso is used as an
universal value to indicate the lack of presence of a value.

It is often used alongside a value of type a to provide a Maybe or
Option abstraction. The type a | Nothing is semantically equivalent to
Expand All @@ -11,12 +12,18 @@ type Nothing

## Checks if the type is an instance of `Nothing`.

Nothing in Enso is used as a universal value to indicate the lack of presence
of a value. This function is primarily useful in the IDE.

> Example
Checking if the value 1 is nothing.

1.is_nothing
is_nothing : Boolean
is_nothing = True
is_nothing = True

## If this is Nothing then returns `function`.

> Example
If the value "Hello" is nothing return "".

"Hello".if_nothing ""
if_nothing : Any
if_nothing ~function = function
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ type Column
defaults to the current type if not provided.
make_binary_op : Text -> Text -> (Column | Any) -> (Sql_Type | Nothing) -> (Sql_Type | Nothing) -> Column
make_binary_op op_kind operand new_type=Nothing operand_type=Nothing =
actual_new_type = if new_type.is_nothing then this.sql_type else new_type
actual_new_type = new_type.if_nothing this.sql_type
case operand of
Column _ _ _ other_expr _ ->
case Helpers.check_integrity this operand of
Expand All @@ -124,7 +124,7 @@ type Column
new_expr = IR.Operation op_kind [this.expression, other_expr]
Column this.name this.connection actual_new_type new_expr this.context
_ ->
actual_operand_type = if operand_type.is_nothing then this.sql_type else operand_type
actual_operand_type = operand_type.if_nothing this.sql_type
other = IR.make_constant actual_operand_type operand
new_expr = IR.Operation op_kind [this.expression, other]
Column this.name this.connection actual_new_type new_expr this.context
Expand All @@ -139,7 +139,7 @@ type Column
operator.
make_unary_op : Text -> Text -> (Sql_Type | Nothing) -> Column
make_unary_op op_kind new_type=Nothing =
actual_new_type = if new_type.is_nothing then this.sql_type else new_type
actual_new_type = new_type.if_nothing this.sql_type
new_expr = IR.Operation op_kind [this.expression]
Column this.name this.connection actual_new_type new_expr this.context

Expand Down Expand Up @@ -605,7 +605,7 @@ type Aggregate_Column_Builder
- new_type: The SQL type of the result column.
make_aggregate : Column -> Text -> Text -> Sql_Type -> Column
make_aggregate column operation name_suffix="_agg" new_type=Nothing =
actual_new_type = if new_type.is_nothing then column.sql_type else new_type
actual_new_type = new_type.if_nothing column.sql_type
expr = IR.Operation operation [column.expression]
case Helpers.ensure_name_is_sane name_suffix of
True ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -507,8 +507,8 @@ type Table
Text -> wrap_elem elem
Column _ _ _ _ _ -> wrap_elem elem
Order_Rule elem Nothing my_order my_nulls ->
chosen_order = if my_order.is_nothing then order else my_order
chosen_nulls = if my_nulls.is_nothing then missing_last else my_nulls
chosen_order = my_order.if_nothing order
chosen_nulls = my_nulls.if_nothing missing_last
[this.resolve elem . expression, order_to_ir chosen_order, missing_to_ir chosen_nulls]
Order_Rule _ _ _ _ ->
Error.throw <| Unsupported_Database_Operation_Error "Custom comparators are not supported in Database"
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ from Standard.Base.Error.Problem_Behavior as Problem_Behavior_Module import Prob
import Standard.Table.Data.Column_Mapping
import Standard.Table.Data.Position

import Standard.Table.Data.Group_By_Key
import Standard.Table.Data.Aggregate_Column

polyglot java import org.enso.table.data.table.Table as Java_Table
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ prepare_aggregate_columns aggregates table =
pass_1 = valid_resolved_aggregate_columns.map c->(if c.new_name.is_nothing then Nothing else unique.make_unique c.new_name)
renamed_columns = pass_1.map_with_index i->name->
agg = valid_resolved_aggregate_columns.at i
new_name = (if name.is_nothing then unique.make_unique (here.default_aggregate_column_name agg) else name)
new_name = name.if_nothing (unique.make_unique (here.default_aggregate_column_name agg))
Pair new_name agg

# Build Problems Output
Expand Down Expand Up @@ -116,7 +116,7 @@ resolve_aggregate table problem_builder aggregate_column =
resolve : (Integer|Text|Column) -> Column ! Internal_Missing_Column_Error
resolve c =
res = Table_Helpers.resolve_column_helper table_columns c problem_builder
if res.is_nothing then Error.throw Internal_Missing_Column_Error else res
res.if_nothing (Error.throw Internal_Missing_Column_Error)

resolve_selector_to_vector : Column_Selector -> [Column] ! Internal_Missing_Column_Error
resolve_selector_to_vector selector =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ rename_columns internal_columns mapping on_problems =

new_names = 0.up_to col_count . map i->
target = index_map.get_or_else i Nothing
if target.is_nothing then target else unique.make_unique target
if target.is_nothing then Nothing else unique.make_unique target

new_names
Column_Mapping.By_Position vec ->
Expand All @@ -179,7 +179,7 @@ rename_columns internal_columns mapping on_problems =
new_names

processed = mapped.map_with_index i->n->
if n.is_nothing then (unique.make_unique (internal_columns.at i).name) else n
n.if_nothing (unique.make_unique (internal_columns.at i).name)

if unique.invalid_names.not_empty then
problem_builder.report_other_warning (Invalid_Output_Column_Names unique.invalid_names.to_vector)
Expand Down

0 comments on commit 23406f0

Please sign in to comment.