diff --git a/packages/types/src/codec/Tuple.spec.ts b/packages/types/src/codec/Tuple.spec.ts index 13edd84944..b602aea801 100644 --- a/packages/types/src/codec/Tuple.spec.ts +++ b/packages/types/src/codec/Tuple.spec.ts @@ -69,12 +69,12 @@ describe('Tuple', () => { expect(tuple.Types).toEqual(['Text', 'U32']); }); - it("doesn't expose filter", () => { - expect(tuple.filter).toThrowError(/is not implemented on Tuple/); + it('exposes filter', () => { + expect(tuple.filter((v) => v.toJSON() === 69)).toEqual([new U32(69)]); }); - it("doesn't expose map", () => { - expect(tuple.map).toThrowError(/is not implemented on Tuple/); + it('exposes map', () => { + expect(tuple.map(v => v.toString())).toEqual(['bazzing', '69']); }); }); diff --git a/packages/types/src/codec/Tuple.ts b/packages/types/src/codec/Tuple.ts index 9093588d80..39d27a5ab8 100644 --- a/packages/types/src/codec/Tuple.ts +++ b/packages/types/src/codec/Tuple.ts @@ -94,7 +94,7 @@ export default class Tuple< * @description Converts the Object to JSON, typically used for RPC transfers */ toJSON (): any { - return this.toArray().map((entry) => + return this.map((entry) => entry.toJSON() ); } @@ -113,7 +113,7 @@ export default class Tuple< */ toU8a (isBare?: boolean): Uint8Array { return u8aConcat( - ...this.toArray().map((entry) => + ...this.map((entry) => entry.toU8a(isBare) ) ); @@ -124,16 +124,20 @@ export default class Tuple< // new instance. /** - * @ignore + * @description Filters the array with the callback + * @param callbackfn The filter function + * @param thisArg The `this` object to apply the result to */ filter (callbackfn: (value: Codec, index: number, array: Array) => any, thisArg?: any): Array { - throw new Error("Method 'filter' is not implemented on Tuple."); + return this.toArray().filter(callbackfn, thisArg); } /** - * @ignore + * @description Maps the array with the callback + * @param callbackfn The mapping function + * @param thisArg The `this` onject to apply the result to */ map (callbackfn: (value: Codec, index: number, array: Array) => U, thisArg?: any): Array { - throw new Error("Method 'map' is not implemented on Tuple."); + return this.toArray().map(callbackfn, thisArg); } }