From cec5e46e45bd02bb1fd755652811bc042f631218 Mon Sep 17 00:00:00 2001 From: rvanasa Date: Tue, 12 Aug 2025 15:07:42 -0600 Subject: [PATCH 1/3] Update migration guide --- doc/md/12-base-core-migration.md | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/doc/md/12-base-core-migration.md b/doc/md/12-base-core-migration.md index d2585cc9929..32e9e7938c2 100644 --- a/doc/md/12-base-core-migration.md +++ b/doc/md/12-base-core-migration.md @@ -7,7 +7,14 @@ sidebar_position: 12 * [GitHub repository](https://github.com/dfinity/motoko-core) * [Documentation](https://internetcomputer.org/docs/motoko/core/) -The `core` package is a new and improved standard library for Motoko, focusing on: +The `core` package is a Helper functions have been added, such as `allValues()`, for each finite type in the `base` package. + +### [`List`](https://internetcomputer.org/docs/motoko/core/List) + +#### New functions +- `binarySearch()` - Search for element in sorted mutable list using binary search + +### [`Nat`](https://internetcomputer.org/docs/motoko/core/Nat) and improved standard library for Motoko, focusing on: * AI-friendly design patterns. * Familiarity coming from languages such as JavaScript, Python, Java, and Rust. * Simplified usage of data structures in stable memory. @@ -130,9 +137,16 @@ The core package introduces a fundamental reorganization of data structures with - `thaw()` → `toVarArray()` - `vals()` → `values()` +#### Parameter ordering changes +- `indexOf`: `(element, array, equal)` → `(array, equal, element)` +- `lastIndexOf`: `(element, array, equal)` → `(array, equal, element)` +- `nextIndexOf`: `(element, array, fromInclusive, equal)` → `(array, equal, element, fromInclusive)` +- `prevIndexOf`: `(element, array, fromExclusive, equal)` → `(array, equal, element, fromExclusive)` + #### New functions - `all()` - Check if all elements satisfy predicate - `any()` - Check if any element satisfies predicate +- `binarySearch()` - Search for element in sorted array using binary search - `compare()` - Compare two arrays - `empty()` - Create empty array - `enumerate()` - Get indexed iterator @@ -324,6 +338,11 @@ persistent actor { - `forErr()` - Apply function to `#err` value - `fromBool()` - Create Result from boolean +### [`Stack`](https://internetcomputer.org/docs/motoko/core/Stack) + +#### Parameter ordering changes +- `contains`: `(stack, element, equal)` → `(stack, equal, element)` + ### [`Text`](https://internetcomputer.org/docs/motoko/core/Text) #### Renamed functions @@ -341,6 +360,17 @@ persistent actor { - `fromList()` - Use `fromIter()` with list iterator instead - `toList()` - Use `toIter()` and convert to list if needed +### [`VarArray`](https://internetcomputer.org/docs/motoko/core/VarArray) + +#### Parameter ordering changes +- `indexOf`: `(element, array, equal)` → `(array, equal, element)` +- `lastIndexOf`: `(element, array, equal)` → `(array, equal, element)` +- `nextIndexOf`: `(element, array, fromInclusive, equal)` → `(array, equal, element, fromInclusive)` +- `prevIndexOf`: `(element, array, fromExclusive, equal)` → `(array, equal, element, fromExclusive)` + +#### New functions +- `binarySearch()` - Search for element in sorted mutable array using binary search + ## Data structure migration examples ### `Buffer` From d515309944f6e6c6a475ba753d46f3212c9fea49 Mon Sep 17 00:00:00 2001 From: rvanasa Date: Tue, 12 Aug 2025 15:13:01 -0600 Subject: [PATCH 2/3] Simplify --- doc/md/12-base-core-migration.md | 39 +++++++------------------------- 1 file changed, 8 insertions(+), 31 deletions(-) diff --git a/doc/md/12-base-core-migration.md b/doc/md/12-base-core-migration.md index 32e9e7938c2..f9663fc8024 100644 --- a/doc/md/12-base-core-migration.md +++ b/doc/md/12-base-core-migration.md @@ -7,14 +7,7 @@ sidebar_position: 12 * [GitHub repository](https://github.com/dfinity/motoko-core) * [Documentation](https://internetcomputer.org/docs/motoko/core/) -The `core` package is a Helper functions have been added, such as `allValues()`, for each finite type in the `base` package. - -### [`List`](https://internetcomputer.org/docs/motoko/core/List) - -#### New functions -- `binarySearch()` - Search for element in sorted mutable list using binary search - -### [`Nat`](https://internetcomputer.org/docs/motoko/core/Nat) and improved standard library for Motoko, focusing on: +The `core` package is a new and improved standard library for Motoko, focusing on: * AI-friendly design patterns. * Familiarity coming from languages such as JavaScript, Python, Java, and Rust. * Simplified usage of data structures in stable memory. @@ -137,16 +130,10 @@ The core package introduces a fundamental reorganization of data structures with - `thaw()` → `toVarArray()` - `vals()` → `values()` -#### Parameter ordering changes -- `indexOf`: `(element, array, equal)` → `(array, equal, element)` -- `lastIndexOf`: `(element, array, equal)` → `(array, equal, element)` -- `nextIndexOf`: `(element, array, fromInclusive, equal)` → `(array, equal, element, fromInclusive)` -- `prevIndexOf`: `(element, array, fromExclusive, equal)` → `(array, equal, element, fromExclusive)` - #### New functions - `all()` - Check if all elements satisfy predicate - `any()` - Check if any element satisfies predicate -- `binarySearch()` - Search for element in sorted array using binary search +- `binarySearch()` - Perform binary search on sorted array - `compare()` - Compare two arrays - `empty()` - Create empty array - `enumerate()` - Get indexed iterator @@ -157,6 +144,12 @@ The core package introduces a fundamental reorganization of data structures with - `join()` - Join arrays from iterator - `toText()` - Convert array to text representation +#### Parameter order changes +- `indexOf(element, array, equal)` → `indexOf(array, equal, element)` +- `lastIndexOf(element, array, equal)` → `lastIndexOf(array, equal, element)` +- `nextIndexOf(element, array, fromInclusive, equal)` → `nextIndexOf(array, equal, element, fromInclusive)` +- `prevIndexOf(element, array, fromExclusive, equal)` → `prevIndexOf(array, equal, element, fromExclusive)` + #### Removed functions - `take()` - Use `sliceToArray()` instead - `sortInPlace()` - Use `VarArray.sortInPlace()` instead @@ -338,11 +331,6 @@ persistent actor { - `forErr()` - Apply function to `#err` value - `fromBool()` - Create Result from boolean -### [`Stack`](https://internetcomputer.org/docs/motoko/core/Stack) - -#### Parameter ordering changes -- `contains`: `(stack, element, equal)` → `(stack, equal, element)` - ### [`Text`](https://internetcomputer.org/docs/motoko/core/Text) #### Renamed functions @@ -360,17 +348,6 @@ persistent actor { - `fromList()` - Use `fromIter()` with list iterator instead - `toList()` - Use `toIter()` and convert to list if needed -### [`VarArray`](https://internetcomputer.org/docs/motoko/core/VarArray) - -#### Parameter ordering changes -- `indexOf`: `(element, array, equal)` → `(array, equal, element)` -- `lastIndexOf`: `(element, array, equal)` → `(array, equal, element)` -- `nextIndexOf`: `(element, array, fromInclusive, equal)` → `(array, equal, element, fromInclusive)` -- `prevIndexOf`: `(element, array, fromExclusive, equal)` → `(array, equal, element, fromExclusive)` - -#### New functions -- `binarySearch()` - Search for element in sorted mutable array using binary search - ## Data structure migration examples ### `Buffer` From ea7731c11c4cf1bdebe57ce2724faf435dfe1fcd Mon Sep 17 00:00:00 2001 From: rvanasa Date: Thu, 14 Aug 2025 12:19:26 -0600 Subject: [PATCH 3/3] Remove reference to 'binarySearch()' for now --- doc/md/12-base-core-migration.md | 1 - 1 file changed, 1 deletion(-) diff --git a/doc/md/12-base-core-migration.md b/doc/md/12-base-core-migration.md index f9663fc8024..452e51b6081 100644 --- a/doc/md/12-base-core-migration.md +++ b/doc/md/12-base-core-migration.md @@ -133,7 +133,6 @@ The core package introduces a fundamental reorganization of data structures with #### New functions - `all()` - Check if all elements satisfy predicate - `any()` - Check if any element satisfies predicate -- `binarySearch()` - Perform binary search on sorted array - `compare()` - Compare two arrays - `empty()` - Create empty array - `enumerate()` - Get indexed iterator