Merge pull request #17556 from DefinitelyTyped/fix-ramda-for-ts-2.4

Fix Ramda for 2.4: evolve and functor map
This commit is contained in:
Paul van Brenk
2017-06-29 14:06:24 -07:00
committed by GitHub
2 changed files with 11 additions and 17 deletions
+7 -6
View File
@@ -55,15 +55,15 @@ declare namespace R {
push(x: string): void;
}
interface Nested<U> {
[index: string]: Nested<U> | (<U>(value: any) => U);
}
interface Lens {
<T, U>(obj: T): U;
set<T, U>(str: string, obj: T): U;
}
type Evolver<T> =
| ((x: T) => T)
| { [K in keyof T]?: Evolver<T[K]> };
// @see https://gist.github.com/donnut/fd56232da58d25ceecf1, comment by @albrow
interface CurriedTypeGuard2<T1, T2, R extends T2> {
(t1: T1): (t2: T2) => t2 is R;
@@ -567,8 +567,9 @@ declare namespace R {
/**
* Creates a new object by evolving a shallow copy of object, according to the transformation functions.
*/
evolve<V>(transformations: Nested<V>, obj: V): Nested<V>;
evolve<V>(transformations: Nested<V>): <V>(obj: V) => Nested<V>;
evolve<V>(transformations: Evolver<V>, obj: V): V;
evolve<V>(transformations: Evolver<V>): <W extends V>(obj: W) => W;
/*
* A function that always returns false. Any passed in parameters are ignored.
*/
+4 -11
View File
@@ -744,13 +744,13 @@ interface Obj {
R.map(double, [1, 2, 3]); // => [2, 4, 6]
// functor
const stringFunctor = {
map: (fn: (c: number) => number) => {
const numberFunctor = {
map: <U>(fn: (c: number) => U) => {
let chars = "Ifmmp!Xpsme".split("");
return chars.map((char) => String.fromCharCode(fn(char.charCodeAt(0)))).join("") as any;
return chars.map(char => fn(char.charCodeAt(0)));
}
};
R.map((x: number) => x - 1, stringFunctor); // => "Hello World"
R.map((x: number) => x - 1, numberFunctor); // => "Hello World"
};
() => {
@@ -2199,10 +2199,3 @@ 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);
}