@@ -21,20 +21,27 @@ export interface Nodeback<E, R> {
21
21
( err : E | null , value ?: R ) : void
22
22
}
23
23
24
- export interface ConcurrentFutureInstance < L , R > {
24
+ export interface Functor < A > {
25
+ input : unknown
26
+ 'fantasy-land/map' < B extends this[ 'input' ] > ( mapper : ( value : A ) => B ) : Functor < B >
27
+ }
28
+
29
+ type Unfunctor < F extends Functor < unknown > , B > = ReturnType < ( F & { input : B } ) [ 'fantasy-land/map' ] >
30
+
31
+ export interface ConcurrentFutureInstance < L , R > extends Functor < R > {
25
32
sequential : FutureInstance < L , R >
26
33
'fantasy-land/ap' < A , B > ( this : ConcurrentFutureInstance < L , ( value : A ) => B > , right : ConcurrentFutureInstance < L , A > ) : ConcurrentFutureInstance < L , B >
27
- 'fantasy-land/map' < RB > ( mapper : ( value : R ) => RB ) : ConcurrentFutureInstance < L , RB >
34
+ 'fantasy-land/map' < RB extends this [ 'input' ] > ( mapper : ( value : R ) => RB ) : ConcurrentFutureInstance < L , RB >
28
35
'fantasy-land/alt' ( right : ConcurrentFutureInstance < L , R > ) : ConcurrentFutureInstance < L , R >
29
36
}
30
37
31
- export interface FutureInstance < L , R > {
38
+ export interface FutureInstance < L , R > extends Functor < R > {
32
39
33
40
/** The Future constructor */
34
41
constructor : FutureTypeRep
35
42
36
43
/** Apply a function to this Future. See https://github.com/fluture-js/Fluture#pipe */
37
- pipe < T > ( fn : ( future : FutureInstance < L , R > ) => T ) : T
44
+ pipe < T > ( fn : ( future : this ) => T ) : T
38
45
39
46
/** Attempt to extract the rejection reason. See https://github.com/fluture-js/Fluture#extractleft */
40
47
extractLeft ( ) : Array < L >
@@ -43,7 +50,7 @@ export interface FutureInstance<L, R> {
43
50
extractRight ( ) : Array < R >
44
51
45
52
'fantasy-land/ap' < A , B > ( this : FutureInstance < L , ( value : A ) => B > , right : FutureInstance < L , A > ) : FutureInstance < L , B >
46
- 'fantasy-land/map' < RB > ( mapper : ( value : R ) => RB ) : FutureInstance < L , RB >
53
+ 'fantasy-land/map' < RB extends this [ 'input' ] > ( mapper : ( value : R ) => RB ) : FutureInstance < L , RB >
47
54
'fantasy-land/alt' ( right : FutureInstance < L , R > ) : FutureInstance < L , R >
48
55
'fantasy-land/bimap' < LB , RB > ( lmapper : ( reason : L ) => LB , rmapper : ( value : R ) => RB ) : FutureInstance < LB , RB >
49
56
'fantasy-land/chain' < LB , RB > ( mapper : ( value : R ) => FutureInstance < LB , RB > ) : FutureInstance < L | LB , RB >
@@ -135,12 +142,10 @@ export function isNever(value: any): boolean
135
142
export function lastly < L > ( cleanup : FutureInstance < L , any > ) : < R > ( action : FutureInstance < L , R > ) => FutureInstance < L , R >
136
143
137
144
/** Map over the resolution value of the given Future or ConcurrentFuture. See https://github.com/fluture-js/Fluture#map */
138
- export function map < RA , RB > ( mapper : ( value : RA ) => RB ) : < T extends FutureInstance < any , RA > | ConcurrentFutureInstance < any , RA > > ( source : T ) =>
139
- T extends FutureInstance < infer L , RA > ?
140
- FutureInstance < L , RB > :
141
- T extends ConcurrentFutureInstance < infer L , RA > ?
142
- ConcurrentFutureInstance < L , RB > :
143
- never ;
145
+ export const map : {
146
+ < B , F extends Functor < unknown > > ( f : Functor < unknown > extends F ? never : ( a : F extends Functor < infer A > ? A : never ) => B ) : ( source : F ) => Unfunctor < F , B >
147
+ < A , B > ( f : ( a : A ) => B ) : < F extends Functor < A > > ( f : F ) => Unfunctor < F , B >
148
+ }
144
149
145
150
/** Map over the rejection reason of the given Future. See https://github.com/fluture-js/Fluture#maprej */
146
151
export function mapRej < LA , LB > ( mapper : ( reason : LA ) => LB ) : < R > ( source : FutureInstance < LA , R > ) => FutureInstance < LB , R >
0 commit comments