import { Either , map as eitherMap , isLeft , isRight } from '@typed/either' ; import { List , map as listMap } from '@typed/list' ; import { Maybe , isJust , isNothing , map as maybeMap } from '@typed/maybe' ; import { curry2 } from '@typed/functions' ; import { isPromiseLike } from '@typed/logic' ; name export const map = curry2 < any , any , any > ( function map ( f , list ) : any { if ( isJust ( list ) || isNothing ( list ) ) return maybeMap ( f , list ) ; if ( isLeft ( list ) || isRight ( list ) ) return eitherMap ( f , list ) ; if ( isPromiseLike ( list ) ) return Promise . resolve ( list . then ( f ) ) ; return listMap ( f , list ) ; } ) ; export type Map = { < A , B > ( f , list ) : Array < B > ; < A , B > ( f , maybe ) : Maybe < B > ; < A , B > ( f , promise ) : Promise < B > ; < A , B , C > ( f , either ) : Either < A , C > ; < A , B > ( f ) : MapArity1 < A , B > ; } ; export type MapArity1 < A , B > = { ( list ) : Array < B > ; ( maybe ) : Maybe < B > ; ( promise ) : Promise < B > ; < C > ( either ) : Either < C , B > ; } ;