ramda: fix inference for mapping a functor

This commit is contained in:
Oliver Joseph Ash
2017-04-04 09:52:00 -04:00
parent 2b5bb39244
commit 9a694ef256
2 changed files with 9 additions and 2 deletions

View File

@@ -15,7 +15,7 @@ declare namespace R {
}
interface Functor<T> {
map<T>(a: any): T;
map<U>(fn: (t: T) => U): Functor<U>;
}
interface ObjectIterator<T, TResult> {

View File

@@ -668,7 +668,7 @@ interface Obj { a: number; b: number };
const stringFunctor = {
map: (fn: (c: number) => number) => {
var chars = "Ifmmp!Xpsme".split("");
return chars.map((char) => String.fromCharCode(fn(char.charCodeAt(0)))).join("");
return chars.map((char) => String.fromCharCode(fn(char.charCodeAt(0)))).join("") as any;
}
};
R.map((x: number) => x-1, stringFunctor); // => "Hello World"
@@ -1985,3 +1985,10 @@ class Why {
R.intersperse(0, [1, 2]); //=> [1, 0, 2]
R.intersperse(0, [1]); //=> [1]
}
{
const functor = {
map: (fn: (x: string) => string) => functor
}
R.map(x => x.trim(), functor)
}