Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

next: Replace Slice type with Iterable type #43

Closed
2 tasks
Tracked by #57
elycruz opened this issue Jun 12, 2021 · 1 comment
Closed
2 tasks
Tracked by #57

next: Replace Slice type with Iterable type #43

elycruz opened this issue Jun 12, 2021 · 1 comment
Assignees
Labels
enhancement groomed Ticket has been groomed for development.

Comments

@elycruz
Copy link
Member

elycruz commented Jun 12, 2021

Complex sum types cause more trouble than it is usually worth, in a low level library - Where ever we have to cast types, internally, means the same has to happen from the outside (in some cases) - for these case we should use simpler, atomic types.

Example case with casting issue:

// types.ts
export type Slice<T = any> = T[] | string;

// reverse.ts
// ...
export const

  reverse = <T>(xs: Slice<T>): Slice<T> => {
    if (!isset(xs) || !xs.length) {
      return xs;
    }
    let i = xs.length - 1;
    if (typeOf(xs) === 'String') {
      let out = of(xs) as string;
      for (; i >= 0; i -= 1) {
        out += xs[i];
      }
      return out;
    }
    const out = of(xs) as T[];
    for (; i >= 0; i -= 1) {
      out.push(xs[i] as T);
    }
    return out;
  }

// Elsewhere (in tests/etc.)
const range0To145 = range(0, 145, 5),

  descNumList = [99].concat(reverse(range0To145)) // type error:
/*  error TS2769: No overload matches this call.
      Overload 1 of 2, '(...items: ConcatArray<number>[]): number[]', gave the following error.
        Argument of type 'Slice<number>' is not assignable to parameter of type 'ConcatArray<number>'.
          Type 'string' is not assignable to type 'ConcatArray<number>'.
      Overload 2 of 2, '(...items: (number | ConcatArray<number>)[]): number[]', gave the following error.
        Argument of type 'Slice<number>' is not assignable to parameter of type 'number | ConcatArray<number>'.
          Type 'string' is not assignable to type 'number | ConcatArray<number>'.
*/

A better approach to the reverse implementation is to only accept Iterable<T>, return T[], and allow the user to decide how to get their string into the method, and alternately supply a reverseStr` method if the method is really required for strings etc..

Acceptance Criteria

  • Remove the slice type and uses.
  • Update method implementations, tests, and methods that use the [Slice] type, to only use the Iterable<T> type.
@elycruz elycruz self-assigned this Jul 7, 2021
elycruz added a commit that referenced this issue Aug 6, 2021
…hods. Updated 'Slice' type to also include 'SliceInterface' type in it's type sum.
elycruz added a commit that referenced this issue Aug 21, 2022
…pe - method now only accepts array of 'T'.
elycruz added a commit that referenced this issue Aug 22, 2022
…accept 'Slice' type - method now only accepts array of 'T'.
elycruz added a commit that referenced this issue Aug 22, 2022
…thods used within their impl. ('unconsr', 'uncons', 'reverse', etc.).

- Added addtional type information to 'breakOnList' impl.
elycruz added a commit that referenced this issue Aug 22, 2022
- Simplified implementations for several methods, and updated them, and their tests so tests are 'green'.
elycruz added a commit that referenced this issue Aug 23, 2022
…e' type, incoming, but to return 'T[][]' (more flexible but still returning 'array of arrays').

- Removed indirection in 'init' method.
elycruz added a commit that referenced this issue Aug 23, 2022
…mberIndexable<T>' instead of 'Slice<T>'.

- Updated 'NumberIndexable' type to also contain 'Lengthable & {readonly [index in number]: string}' - enables this type to sit in place of 'string' type, where it makes sense (e.g., 'intersperse', and other methods).
elycruz added a commit that referenced this issue Aug 24, 2022
…e but instead treat incoming 'T[][]' as 'Slice<T>[]'.

- Updated types in 'string' module's failing tests.
elycruz added a commit that referenced this issue Aug 24, 2022
- Simplified logic in 'insertBy' method.
- Reversed some logic in 'intersect' method.
elycruz added a commit that referenced this issue Aug 24, 2022
elycruz added a commit that referenced this issue Aug 24, 2022
…anagement/use of array types.

- Updated 'map' implementation to only work with array types.
- Updated 'map' tests.
elycruz added a commit that referenced this issue Aug 24, 2022
…anagement/use of array types.

- Updated 'map' implementation to only work with array types.
- Updated 'map' tests.
- Also all [unstable] progress on updating 'map' method related methods is in progress - Types have to be updated for all these methods.
elycruz added a commit that referenced this issue Aug 26, 2022
elycruz added a commit that referenced this issue Aug 26, 2022
…rk - The forward is to simplify the 'fjl/src/list/' methods to just work for array's, mixing and matching types is proving to be a major headache as the typescript compiler is now a bit stricter than it used to be - All array methods to only work on arrays from hear-on-out, unless we find a way to make them work seamlessly (without requiring typecasting all over the place) in all required scenarios (for TypedArray, string, and Array types, etc.).
elycruz added a commit that referenced this issue Aug 26, 2022
…onal-jslib/fjl into issue-#43-normalize_array_methods
elycruz added a commit that referenced this issue Aug 26, 2022
- Progress on changing array types, in 'src/fjl/list/' - Progress will
now shift to make all 'list' methods work only with array types.
elycruz added a commit that referenced this issue Aug 26, 2022
…onal-jslib/fjl into issue-#43-normalize_array_methods
elycruz added a commit that referenced this issue Aug 26, 2022
…tils' to just accept pure array types.

Cleaned up formatting in some tests.
elycruz added a commit that referenced this issue Aug 26, 2022
…s - most methods updated here, except ones where it made sense to keep the (Slice) type.

- Progress on tests cleanup to 'green' state.
elycruz added a commit that referenced this issue Aug 27, 2022
…hough modified to absolutely work for strings, arrays, or objects meeting the requirements - type need fine tweaking to match the intersected types' internals ('concat()', '[index: number]: ...', types etc.).

- Progress on updating existing methods to have 'green' tests.
elycruz added a commit that referenced this issue Aug 27, 2022
- Updated TypedArray type's 'concat' method declaration.
elycruz added a commit that referenced this issue Aug 27, 2022
- Cleaned tests for 'permutations' method.
elycruz added a commit that referenced this issue Aug 27, 2022
- Updated some methods to take 'Slice' type.
elycruz added a commit that referenced this issue Aug 28, 2022
…lementaitons and types)and updates to tests towards 'green' tests.
elycruz added a commit that referenced this issue Aug 28, 2022
…' - Makes type more flexible.

- Updated 'group', 'groupBy', 'intercalate', and 'intersperse' types, to allow 'Slice' type.
- Updated tests for, the above, and 'concatMap'.
elycruz added a commit that referenced this issue Aug 28, 2022
elycruz added a commit that referenced this issue Aug 28, 2022
elycruz added a commit that referenced this issue Jan 22, 2023
- Tightened up some types - mapAccumL et al.
- Cleaned up some tests.
@elycruz elycruz changed the title next: Remove support for Slice type and any Sum types in base types next: Limit use of Slice type and any Sum types in base types Apr 8, 2023
@elycruz elycruz added the groomed Ticket has been groomed for development. label Dec 30, 2023
@elycruz elycruz mentioned this issue Dec 30, 2023
41 tasks
@elycruz elycruz changed the title next: Limit use of Slice type and any Sum types in base types next: Remove Replace Slice type with Iterable type Feb 25, 2024
@elycruz elycruz changed the title next: Remove Replace Slice type with Iterable type next: Replace Slice type with Iterable type Feb 27, 2024
elycruz added a commit that referenced this issue Feb 28, 2024
…precated 'Nameable' and 'TypeRef' related types, and added [pseudo] standalone (tsc) tests for 'Slice' type.
@elycruz
Copy link
Member Author

elycruz commented May 27, 2024

Issue no longer required - We have found a way to continue using the Slice type by having it extend the platform's Iterable<T> type.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement groomed Ticket has been groomed for development.
Projects
Status: Done
Development

No branches or pull requests

1 participant