Skip to content

Commit

Permalink
Update the TS Functor interface to hide its guts
Browse files Browse the repository at this point in the history
Switch to using a symbol instead of the 'input' property, to prevent
this property, which is just used for passing around type information,
from showing up in auto-completion as if it could be used at runtime.
  • Loading branch information
Avaq committed Jan 8, 2021
1 parent 8eef14a commit 5b76764
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,19 @@ export interface Nodeback<E, R> {
(err: E | null, value?: R): void
}

declare const $functor: unique symbol

export interface Functor<A> {
input: unknown
'fantasy-land/map'<B extends this['input']>(mapper: (value: A) => B): Functor<B>
[$functor]: unknown
'fantasy-land/map'<B extends this[typeof $functor]>(mapper: (value: A) => B): Functor<B>
}

type Unfunctor<F extends Functor<unknown>, B> = ReturnType<(F & { input: B })['fantasy-land/map']>
type Unfunctor<F extends Functor<unknown>, B> = ReturnType<(F & { [$functor]: B })['fantasy-land/map']>

export interface ConcurrentFutureInstance<L, R> extends Functor<R> {
sequential: FutureInstance<L, R>
'fantasy-land/ap'<A, B>(this: ConcurrentFutureInstance<L, (value: A) => B>, right: ConcurrentFutureInstance<L, A>): ConcurrentFutureInstance<L, B>
'fantasy-land/map'<RB extends this['input']>(mapper: (value: R) => RB): ConcurrentFutureInstance<L, RB>
'fantasy-land/map'<RB extends this[typeof $functor]>(mapper: (value: R) => RB): ConcurrentFutureInstance<L, RB>
'fantasy-land/alt'(right: ConcurrentFutureInstance<L, R>): ConcurrentFutureInstance<L, R>
}

Expand All @@ -50,7 +52,7 @@ export interface FutureInstance<L, R> extends Functor<R> {
extractRight(): Array<R>

'fantasy-land/ap'<A, B>(this: FutureInstance<L, (value: A) => B>, right: FutureInstance<L, A>): FutureInstance<L, B>
'fantasy-land/map'<RB extends this['input']>(mapper: (value: R) => RB): FutureInstance<L, RB>
'fantasy-land/map'<RB extends this[typeof $functor]>(mapper: (value: R) => RB): FutureInstance<L, RB>
'fantasy-land/alt'(right: FutureInstance<L, R>): FutureInstance<L, R>
'fantasy-land/bimap'<LB, RB>(lmapper: (reason: L) => LB, rmapper: (value: R) => RB): FutureInstance<LB, RB>
'fantasy-land/chain'<LB, RB>(mapper: (value: R) => FutureInstance<LB, RB>): FutureInstance<L | LB, RB>
Expand Down

0 comments on commit 5b76764

Please sign in to comment.