Skip to content

Commit

Permalink
Align Vector API with design, add some extra functions from AoC (#4026)
Browse files Browse the repository at this point in the history
**Vector**
- Adjusted `Vector.sort` to be `Vector.sort order on by`.
- Adjusted other sort to use `order` for direction argument.
- Added `insert`, `remove`, `index_of` and `last_index_of` to `Vector`.
- Added `start` and `if_missing` arguments to `find` on `Vector`, and adjusted default is `Not_Found` error.
- Added type checking to `+` on `Vector`.
- Altered `first`, `second` and `last` to error with `Index_Out_Of_Bounds` on `Vector`.
- Removed `sum`, `exists`, `head`, `init`, `tail`, `rest`, `append`, `prepend` from `Vector`.

**Pair**
- Added `last`, `any`, `all`, `contains`, `find`, `index_of`, `last_index_of`, `reverse`, `each`, `fold` and `reduce` to `Pair`.
- Added `get` to `Pair`.

**Range**
- Added `first`, `second`, `index_of`, `last_index_of`, `reverse` and `reduce` to `Range`.
- Added `at` and `get` to `Range`.
- Added `start` and `if_missing` arguments to `find` on `Range`.
- Simplified `last` and `length` of `Range`.
- Removed `exists` from `Range`.

**List**
- Added `second`, `find`, `index_of`, `last_index_of`, `reverse` and `reduce` to `Range`.
- Added `at` and `get` to `List`.
- Removed `exists` from `List`.
- Made `all` short-circuit if any fail on `List`.
- Altered `is_empty` to not compute the length of `List`.
- Altered `first`, `tail`, `head`, `init` and `last` to error with `Index_Out_Of_Bounds` on `List`.

**Others**
- Added `first`, `second`, `last`, `get` to `Text`.
- Added wrapper methods to the Random_Number_Generator so you can get random values more easily.
- Adjusted `Aggregate_Column` to operate on the first column by default.
- Added `contains_key` to `Map`.
- Added ALIAS to `row_count` and `order_by`.
  • Loading branch information
jdunkerley authored Jan 12, 2023
1 parent a3de151 commit c4c35c9
Show file tree
Hide file tree
Showing 51 changed files with 1,551 additions and 496 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,8 @@
- [Overhauled the JSON support (now based of JavaScript), `Data.fetch` and other
minor tweaks][3987]
- [Enable Date, Time and DateTime to be read and written to Excel.][3997]
- [Aligning core APIs for Vector, List and Range. Adding some missing functions
to the types.][4026]
- [Implemented `Table.distinct` for Database backends.][4027]

[debug-shortcuts]:
Expand Down Expand Up @@ -424,6 +426,7 @@
[3987]: https://github.com/enso-org/enso/pull/3987
[3997]: https://github.com/enso-org/enso/pull/3997
[4013]: https://github.com/enso-org/enso/pull/4013
[4026]: https://github.com/enso-org/enso/pull/4026
[4027]: https://github.com/enso-org/enso/pull/4027

#### Enso Compiler
Expand Down
9 changes: 5 additions & 4 deletions distribution/lib/Standard/Base/0.0.0-dev/package.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,21 @@ component-groups:
- Standard.Base.Data.Text.Regex.escape
- Select:
exports:
- Standard.Base.Data.Vector.Vector.tail
- Standard.Base.Data.Vector.Vector.at
- Standard.Base.Data.Vector.Vector.get
- Standard.Base.Data.Vector.Vector.filter
- Standard.Base.Data.Vector.Vector.find
- Standard.Base.Data.Vector.Vector.at
- Standard.Base.Data.Vector.Vector.take
- Standard.Base.Data.Vector.Vector.drop
- Standard.Base.Data.Vector.Vector.partition
- Standard.Base.Data.Vector.Vector.distinct
- Join:
exports:
- Standard.Base.Data.Vector.Vector.append
- Standard.Base.Data.Vector.Vector.prepend
- Standard.Base.Data.Vector.Vector.zip
- Transform:
exports:
- Standard.Base.Data.Vector.Vector.insert
- Standard.Base.Data.Vector.Vector.remove
- Standard.Base.Data.Vector.Vector.map
- Standard.Base.Data.Vector.Vector.sort
- Standard.Base.Data.Vector.Vector.distinct
Expand Down
2 changes: 1 addition & 1 deletion distribution/lib/Standard/Base/0.0.0-dev/src/Data.enso
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ fetch uri method=HTTP_Method.Get headers=[] parse=True =

if response.code.is_success.not then Error.throw (Request_Error.Error "Status Code" ("Request failed with status code: " + response.code + ". " + response.body.to_text)) else
response_headers = response.headers
content_type = response_headers.find h-> "Content-Type".equals_ignore_case h.name
content_type = response_headers.find if_missing=Nothing h-> "Content-Type".equals_ignore_case h.name
if (parse == False) || (content_type == Nothing) then response else
format = Auto_Detect.get_web_parser content_type.value uri
if format == Nothing then response else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ invert_range_selection : Vector Range -> Integer -> Boolean -> Vector Range
invert_range_selection ranges length needs_sorting =
sorted = if needs_sorting then sort_and_merge_ranges ranges else ranges
ranges_with_sentinels = [0.up_to 0] + sorted + [length.up_to length]
ranges_with_sentinels.zip ranges_with_sentinels.tail prev-> next->
ranges_with_sentinels.zip (ranges_with_sentinels.drop 1) prev-> next->
prev.end.up_to next.start

## PRIVATE
Expand All @@ -120,7 +120,7 @@ sort_and_merge_ranges ranges =
if sorted.is_empty then [] else
current_ref = Ref.new sorted.first
builder = Vector.new_builder
sorted.tail.each range->
sorted.drop 1 . each range->
current = current_ref.get
case range.start <= current.end of
True -> current_ref.put (current.start.up_to (Math.max current.end range.end))
Expand Down
8 changes: 4 additions & 4 deletions distribution/lib/Standard/Base/0.0.0-dev/src/Data/Json.enso
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,10 @@ type JS_Object
from_pairs : Vector -> JS_Object
from_pairs pairs =
js_object = pairs.fold new_object current->pair->
case pair.at 0 of
case pair.first of
text : Text ->
set_value current text (pair.at 1).to_js_object
current
js_value = pair.second.to_js_object
set_value current text js_value
_ -> Error.throw (Illegal_Argument.Error "JS_Object.from_pairs: key must be a Text value")
JS_Object.Value js_object

Expand Down Expand Up @@ -243,7 +243,6 @@ make_javascript enso_object =
value = enso_object.get key
js_value = make_javascript value
set_value current key js_value
current
_ : Vector -> enso_object.map make_javascript
_ : Array -> Vector.from_polyglot_array enso_object . map make_javascript
_ -> enso_object
Expand All @@ -265,6 +264,7 @@ foreign js get_value object key = """

foreign js set_value object key value = """
object[key] = value
return object

foreign js get_property_names object = """
return Object.getOwnPropertyNames(object)
Loading

0 comments on commit c4c35c9

Please sign in to comment.