Skip to content

Commit

Permalink
Add get_value to Table to allow easy single cell reading.
Browse files Browse the repository at this point in the history
Fix missing imports.
  • Loading branch information
jdunkerley committed Mar 2, 2024
1 parent 03f63f2 commit e3ecc67
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ import project.Network.HTTP.Response_Body.Response_Body
import project.Network.HTTP.Response_Body.Throw_Unsupported_Error
import project.Network.URI.URI
import project.Nothing.Nothing
import project.System.File.Existing_File_Behavior.Existing_File_Behavior
import project.System.File.File
import project.System.File.Generic.Writable_File.Writable_File
import project.System.File_Format.Auto_Detect
import project.System.File_Format.File_Format
import project.System.File_Format.Infer
Expand Down
22 changes: 22 additions & 0 deletions distribution/lib/Standard/Table/0.0.0-dev/src/Data/Table.enso
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,28 @@ type Table
_ -> Error.throw (Illegal_Argument.Error "expected 'selector' to be either a Text or an Integer, but got "+(Meta.get_simple_type_name selector)+".")
if java_column.is_nothing then if_missing else Column.Value java_column

## ALIAS get cell, cell value
ICON select_column
Gets a value from the table.

Arguments:
- selector: The name or index of the column.
- index: The index of the value to get within the column.
- if_missing: The value to use if the selector isn't present.

> Example
Get the names of all of the items from the shop inventory.

import Standard.Examples

example_at = Examples.inventory_table.get_value "item_name" 4
@selector Widget_Helpers.make_column_name_selector
@index (t-> Widget.Numeric_Input minimum=0 maximum=t.row_count-1)
get_value : Text | Integer -> Integer -> Any -> Column | Any
get_value self selector=0 index=0 ~if_missing=Nothing =
col = self.get selector if_missing=Nothing
if col.is_nothing then if_missing else col.get index if_missing

## GROUP Standard.Base.Selections
ICON select_column
Gets the first column.
Expand Down

0 comments on commit e3ecc67

Please sign in to comment.