Skip to content

Commit

Permalink
fix typing for #ap method
Browse files Browse the repository at this point in the history
  • Loading branch information
Hypercubed committed Feb 27, 2022
1 parent 9c90589 commit 7a22377
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 3 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ CHANGELOG
=========

## HEAD (Unreleased)
_(none)_
* Fix typing for `#ap`

---

Expand Down
3 changes: 2 additions & 1 deletion src/lib/randomator.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,8 @@ describe('Randomator', () => {

test('#ap', () => {
const r$ = ab$.map(_ => _.toUpperCase());
expect(r$.ap('c')).toMatch(/C/);
const v = r$.ap('c');
expect(v).toMatch(/C/);
});

test('#ap throws on unmapped randomator', () => {
Expand Down
9 changes: 9 additions & 0 deletions src/lib/randomator.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,12 @@ expectType<number>(j$());
// toArray
const k = e$.toArray(5);
expectType<number[]>(k);

// switchMap
const l$ = e$.map(n => n + n);
const m$ = l$.switchMap(a$);
expectType<string>(m$());

// ap
const n = l$.ap(10);
expectType<number>(n);
2 changes: 1 addition & 1 deletion src/lib/randomator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export class Randomator<T = unknown> extends Function implements Iterator<T> {
* @param value A value
* @returns
*/
ap<U>(value: unknown): U {
ap(value: unknown): T {
const mapping = this[MappingFunction];
if (!mapping) {
throw new Error('ap can only be called on a mapped Randomator');
Expand Down

0 comments on commit 7a22377

Please sign in to comment.