[ramda]: Improve map definition

This commit is contained in:
Miloslav Nenadal
2017-07-07 14:42:36 +02:00
parent 66fe42e92c
commit e9ecb63b33
2 changed files with 20 additions and 0 deletions

View File

@@ -919,6 +919,8 @@ declare namespace R {
map<T, U>(fn: (x: T) => U, list: T[]): U[];
map<T, U>(fn: (x: T) => U, obj: Functor<T>): Functor<U>; // used in functors
map<T, U>(fn: (x: T) => U): (list: T[]) => U[];
map<T extends object, U extends {[P in keyof T]: U[P]}>(fn: (x: T[keyof T]) => U[keyof T], obj: T): U;
map<T extends object, U extends {[P in keyof T]: U[P]}>(fn: (x: T[keyof T]) => U[keyof T]): (obj: T) => U;
/**
* The mapAccum function behaves like a combination of map and reduce.

View File

@@ -753,6 +753,24 @@ interface Obj {
R.map((x: number) => x - 1, numberFunctor); // => "Hello World"
};
() => {
interface A {
a: number;
b: number;
}
interface B {
a: string;
b: string;
}
R.map<A, A>(R.inc, {a: 1, b: 2});
R.map<A, B>(R.toString, {a: 1, b: 2});
R.map<A, A>(R.inc)({a: 1, b: 2});
R.map<A, B>(R.toString)({a: 1, b: 2});
};
() => {
let digits = ["1", "2", "3", "4"];