diff --git a/types/ramda/index.d.ts b/types/ramda/index.d.ts index fcae7ef5c0..eabd0560a2 100644 --- a/types/ramda/index.d.ts +++ b/types/ramda/index.d.ts @@ -1,4 +1,4 @@ -// Type definitions for ramda +// Type definitions for ramda 0.24 // Project: https://github.com/donnut/typescript-ramda // Definitions by: Erwin Poeze // Matt DeKrey @@ -9,58 +9,45 @@ // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.2 -declare var R: R.Static; +declare let R: R.Static; declare namespace R { type Ord = number | string | boolean; - type Path = (number | string)[]; + type Path = Array<(number | string)>; - interface ListIterator { - (value: T, index: number, list: T[]): TResult; - } + type ListIterator = (value: T, index: number, list: T[]) => TResult; interface Functor { map(fn: (t: T) => U): Functor; } - interface ObjectIterator { - (element: T, key: string, obj: Dictionary): Dictionary; - } + type ObjectIterator = (element: T, key: string, obj: Dictionary) => Dictionary; - interface KeyValuePair extends Array { 0 : K; 1 : V; } + interface KeyValuePair extends Array { 0: K; 1: V; + } interface ArrayLike { nodeType: number; } - interface Arity0Fn { - (): any - } + type Arity0Fn = () => any; - interface Arity1Fn { - (a: any): any - } + type Arity1Fn = (a: any) => any; - interface Arity2Fn { - (a: any, b: any): any - } + type Arity2Fn = (a: any, b: any) => any; interface ObjFunc { - [index:string]: Function; + [index: string]: (...a: any[]) => any; } interface ObjFunc2 { - [index:string]: (x: any, y: any) => boolean; + [index: string]: (x: any, y: any) => boolean; } - interface Pred { - (...a: any[]): boolean; - } + type Pred = (...a: any[]) => boolean; - interface ObjPred { - (value: any, key: string): boolean; - } + type ObjPred = (value: any, key: string) => boolean; interface Dictionary { [index: string]: T; @@ -71,12 +58,12 @@ declare namespace R { } interface Nested { - [index: string]: Nested|{(value: any): U}; + [index: string]: Nested | ((value: any) => U); } interface Lens { - (obj: T): U; - set(str: string, obj: T): U; + (obj: T): U; + set(str: string, obj: T): U; } // @see https://gist.github.com/donnut/fd56232da58d25ceecf1, comment by @albrow @@ -150,30 +137,29 @@ declare namespace R { (t1: T1, t2: T2, t3: T3, t4: T4, t5: T5, t6: T6): R; } - interface Reduced {} + interface Reduced { + [index: number]: any; + [index: string]: any; + } interface Static { + /** + * Adds two numbers (or strings). Equivalent to a + b but curried. + */ + add(a: number, b: number): number; + add(a: string, b: string): string; + add(a: number): (b: number) => number; + add(a: string): (b: string) => string; - /** - * Adds two numbers (or strings). Equivalent to a + b but curried. - */ - add(a: number, b: number): number; - add(a: string, b: string): string; - add(a: number): (b: number) => number; - add(a: string): (b: string) => string; - - /** - * Creates a new list iteration function from an existing one by adding two new parameters to its callback - * function: the current index, and the entire list. - */ - addIndex(fn: (f: (item: T) => U, list: T[]) => U[] ) - : CurriedFunction2<(item: T, idx: number, list?: T[]) => U, T[], U[]>; - /* Special case for forEach */ - addIndex(fn: (f: (item: T) => void, list: T[]) => T[]) - : CurriedFunction2<(item: T, idx: number, list?: T[]) => void, T[], T[]>; - /* Special case for reduce */ - addIndex(fn: (f: (acc:U, item: T) => U, aci:U, list: T[]) => U) - : CurriedFunction3<(acc:U, item: T, idx: number, list?: T[]) => U, U, T[], U>; + /** + * Creates a new list iteration function from an existing one by adding two new parameters to its callback + * function: the current index, and the entire list. + */ + addIndex(fn: (f: (item: T) => U, list: T[]) => U[]): CurriedFunction2<(item: T, idx: number, list?: T[]) => U, T[], U[]>; + /* Special case for forEach */ + addIndex(fn: (f: (item: T) => void, list: T[]) => T[]): CurriedFunction2<(item: T, idx: number, list?: T[]) => void, T[], T[]>; + /* Special case for reduce */ + addIndex(fn: (f: (acc: U, item: T) => U, aci: U, list: T[]) => U): CurriedFunction3<(acc: U, item: T, idx: number, list?: T[]) => U, U, T[], U>; /** * Applies a function to the value at the given index of an array, returning a new copy of the array with the @@ -193,18 +179,17 @@ declare namespace R { */ allPass(preds: Pred[]): Pred; - /** - * Returns a function that always returns the given value. - */ + /** + * Returns a function that always returns the given value. + */ always(val: T): () => T; - /** * A function that returns the first argument if it's falsy otherwise the second argument. Note that this is * NOT short-circuited, meaning that if expressions are passed they are both evaluated. */ - and(fn1: T, val2: boolean|any): boolean; - and(fn1: T): (val2: boolean|any) => boolean; + and any); }>(fn1: T, val2: boolean | any): boolean; + and any); }>(fn1: T): (val2: boolean | any) => boolean; /** * Returns true if at least one of elements of the list match the predicate, false otherwise. @@ -220,9 +205,8 @@ declare namespace R { /** * ap applies a list of functions to a list of values. */ - ap(fns: ((a: T) => U)[], vs: T[]): U[]; - ap(fns: ((a: T) => U)[]): (vs: T[]) => U[]; - + ap(fns: Array<((a: T) => U)>, vs: T[]): U[]; + ap(fns: Array<((a: T) => U)>): (vs: T[]) => U[]; /** * Returns a new list, composed of n-tuples of consecutive elements If n is greater than the length of the list, @@ -234,9 +218,9 @@ declare namespace R { /** * Returns a new list containing the contents of the given list, followed by the given element. */ - append(el: U, list: T[]): (T & U)[]; - append(el: U): (list: T[]) => (T & U)[]; - append(el: U): (list: T[]) => (T & U)[]; + append(el: U, list: T[]): Array<(T & U)>; + append(el: U): (list: T[]) => Array<(T & U)>; + append(el: U): (list: T[]) => Array<(T & U)>; /** * Applies function fn to the argument list args. This is useful for creating a fixed-arity function from @@ -255,24 +239,23 @@ declare namespace R { /** * Makes a shallow clone of an object, setting or overriding the specified property with the given value. */ - assoc(prop: K, val: T, obj: U): Record & U; - assoc(prop: K): (val: T, obj: U) => Record & U; - assoc(prop: K, val: T): (obj: U) => Record & U; - + assoc(prop: K, val: T, obj: U): Record & U; + assoc(prop: K): (val: T, obj: U) => Record & U; + assoc(prop: K, val: T): (obj: U) => Record & U; /** * Makes a shallow clone of an object, setting or overriding the nodes required to create the given path, and * placing the specific value at the tail end of that path. */ - assocPath(path: Path, val: T, obj: U): U; - assocPath(path: Path, val: T): (obj: U) => U; - assocPath(path: Path): CurriedFunction2; + assocPath(path: Path, val: T, obj: U): U; + assocPath(path: Path, val: T): (obj: U) => U; + assocPath(path: Path): CurriedFunction2; /** * Wraps a function of any arity (including nullary) in a function that accepts exactly 2 * parameters. Any extraneous parameters will not be passed to the supplied function. */ - binary(fn: (...args: any[]) => any): Function; + binary(fn: (...args: any[]) => any): (...a: any[]) => any; /** * Creates a function that is bound to a context. Note: R.bind does not provide the additional argument-binding @@ -280,7 +263,6 @@ declare namespace R { */ bind(thisObj: T, fn: (...args: any[]) => any): (...args: any[]) => any; - /** * A function wrapping calls to the two functions in an && operation, returning the result of the first function * if it is false-y and the result of the second function otherwise. Note that this is short-circuited, meaning @@ -294,7 +276,7 @@ declare namespace R { * as a converging function for R.converge: the left branch can produce a function while the right branch * produces a value to be passed to that function as an argument. */ - call(fn: (...args: any[])=> (...args: any[]) => any, ...args: any[]): any; + call(fn: (...args: any[]) => (...args: any[]) => any, ...args: any[]): any; /** * `chain` maps a function over a list and concatenates the results. @@ -331,12 +313,12 @@ declare namespace R { * - applying g to zero or more arguments will give false if applying the same arguments to f gives * a logical true value. */ - complement(pred: (...args: any[]) => boolean): (...args: any[]) => boolean + complement(pred: (...args: any[]) => boolean): (...args: any[]) => boolean; /** * Performs right-to-left function composition. The rightmost function may have any arity; the remaining * functions must be unary. - */ + */ compose(fn0: (x0: V0) => T1): (x0: V0) => T1; compose(fn0: (x0: V0, x1: V1) => T1): (x0: V0, x1: V1) => T1; compose(fn0: (x0: V0, x1: V1, x2: V2) => T1): (x0: V0, x1: V1, x2: V2) => T1; @@ -358,8 +340,18 @@ declare namespace R { compose(fn4: (x: T4) => T5, fn3: (x: T3) => T4, fn2: (x: T2) => T3, fn1: (x: T1) => T2, fn0: (x0: V0, x1: V1, x2: V2) => T1): (x0: V0, x1: V1, x2: V2) => T5; compose(fn5: (x: T5) => T6, fn4: (x: T4) => T5, fn3: (x: T3) => T4, fn2: (x: T2) => T3, fn1: (x: T1) => T2, fn0: (x: V0) => T1): (x: V0) => T6; - compose(fn5: (x: T5) => T6, fn4: (x: T4) => T5, fn3: (x: T3) => T4, fn2: (x: T2) => T3, fn1: (x: T1) => T2, fn0: (x0: V0, x1: V1) => T1): (x0: V0, x1: V1) => T6; - compose(fn5: (x: T5) => T6, fn4: (x: T4) => T5, fn3: (x: T3) => T4, fn2: (x: T2) => T3, fn1: (x: T1) => T2, fn0: (x0: V0, x1: V1, x2: V2) => T1): (x0: V0, x1: V1, x2: V2) => T6; + compose(fn5: (x: T5) => T6, + fn4: (x: T4) => T5, + fn3: (x: T3) => T4, + fn2: (x: T2) => T3, + fn1: (x: T1) => T2, + fn0: (x0: V0, x1: V1) => T1): (x0: V0, x1: V1) => T6; + compose(fn5: (x: T5) => T6, + fn4: (x: T4) => T5, + fn3: (x: T3) => T4, + fn2: (x: T2) => T3, + fn1: (x: T1) => T2, + fn0: (x0: V0, x1: V1, x2: V2) => T1): (x0: V0, x1: V1, x2: V2) => T6; /** * TODO composeK @@ -369,7 +361,6 @@ declare namespace R { * TODO composeP */ - /** * Returns a new list consisting of the elements of the first list followed by the elements * of the second. @@ -385,21 +376,18 @@ declare namespace R { * point fn returns the result of applying its arguments to the corresponding transformer. If none of the predicates * matches, fn returns undefined. */ - cond(fns: [Pred, Function][]): Function; - + cond(fns: Array<[Pred, (...a: any[]) => any]>): (...a: any[]) => any; /** * Wraps a constructor function inside a curried function that can be called with the same arguments and returns the same type. */ - construct(fn: Function): Function; - + construct(fn: (...a: any[]) => any): (...a: any[]) => any; /** * Wraps a constructor function inside a curried function that can be called with the same arguments and returns the same type. * The arity of the function returned is specified to allow using variadic constructor functions. */ - constructN(n: number, fn: Function): Function; - + constructN(n: number, fn: (...a: any[]) => any): (...a: any[]) => any; /** * Returns `true` if the specified item is somewhere in the list, `false` otherwise. @@ -416,7 +404,7 @@ declare namespace R { * function is applied to those same arguments. The results of each branching function * are passed as arguments to the converging function to produce the return value. */ - converge(after: Function, fns: Function[]): Function; + converge(after: ((...a: any[]) => any), fns: Array<((...a: any[]) => any)>): (...a: any[]) => any; /** * Counts the elements of a list according to how many match each value @@ -425,32 +413,30 @@ declare namespace R { * the list. Note that all keys are coerced to strings because of how * JavaScript objects work. */ - countBy(fn: (a: any) => string|number, list: any[]): any; - countBy(fn: (a: any) => string|number): (list: any[]) => any; + countBy(fn: (a: any) => string | number, list: any[]): any; + countBy(fn: (a: any) => string | number): (list: any[]) => any; /** * Returns a curried equivalent of the provided function. The curried function has two unusual capabilities. * First, its arguments needn't be provided one at a time. */ - curry(fn: (a: T1, b: T2) => b is TResult): CurriedTypeGuard2 - curry(fn: (a: T1, b: T2, c: T3) => c is TResult): CurriedTypeGuard3 - curry(fn: (a: T1, b: T2, c: T3, d: T4) => d is TResult): CurriedTypeGuard4 - curry(fn: (a: T1, b: T2, c: T3, d: T4, e: T5) => e is TResult): CurriedTypeGuard5 - curry(fn: (a: T1, b: T2, c: T3, d: T4, e: T5, f: T6) => f is TResult): CurriedTypeGuard6 - curry(fn: (a: T1, b: T2) => TResult): CurriedFunction2 - curry(fn: (a: T1, b: T2, c: T3) => TResult): CurriedFunction3 - curry(fn: (a: T1, b: T2, c: T3, d: T4) => TResult): CurriedFunction4 - curry(fn: (a: T1, b: T2, c: T3, d: T4, e: T5) => TResult): CurriedFunction5 - curry(fn: (a: T1, b: T2, c: T3, d: T4, e: T5, f: T6) => TResult): CurriedFunction6 - curry(fn: Function): Function - + curry(fn: (a: T1, b: T2) => b is TResult): CurriedTypeGuard2; + curry(fn: (a: T1, b: T2, c: T3) => c is TResult): CurriedTypeGuard3; + curry(fn: (a: T1, b: T2, c: T3, d: T4) => d is TResult): CurriedTypeGuard4; + curry(fn: (a: T1, b: T2, c: T3, d: T4, e: T5) => e is TResult): CurriedTypeGuard5; + curry(fn: (a: T1, b: T2, c: T3, d: T4, e: T5, f: T6) => f is TResult): CurriedTypeGuard6; + curry(fn: (a: T1, b: T2) => TResult): CurriedFunction2; + curry(fn: (a: T1, b: T2, c: T3) => TResult): CurriedFunction3; + curry(fn: (a: T1, b: T2, c: T3, d: T4) => TResult): CurriedFunction4; + curry(fn: (a: T1, b: T2, c: T3, d: T4, e: T5) => TResult): CurriedFunction5; + curry(fn: (a: T1, b: T2, c: T3, d: T4, e: T5, f: T6) => TResult): CurriedFunction6; + curry(fn: (...a: any[]) => any): (...a: any[]) => any; /** * Returns a curried equivalent of the provided function, with the specified arity. The curried function has * two unusual capabilities. First, its arguments needn't be provided one at a time. */ - curryN(length: number, fn: (...args: any[]) => any): Function; - + curryN(length: number, fn: (...args: any[]) => any): (...a: any[]) => any; /** * Decrements its argument. @@ -461,8 +447,8 @@ declare namespace R { * Returns the second argument if it is not null or undefined. If it is null or undefined, the * first (default) argument is returned. */ - defaultTo(a: T, b: U): T|U - defaultTo(a: T): (b: U) => T|U + defaultTo(a: T, b: U): T | U; + defaultTo(a: T): (b: U) => T | U; /** * Finds the set (i.e. no duplicates) of all elements in the first list not contained in the second list. @@ -504,7 +490,7 @@ declare namespace R { drop(n: number): { (xs: string): string; (xs: T[]): T[]; - } + }; /** * Returns a list containing all but the last n elements of the given list. @@ -514,7 +500,7 @@ declare namespace R { dropLast(n: number): { (xs: T[]): T[]; (xs: string): string; - } + }; /** * Returns a new list containing all but last then elements of a given list, passing each value from the @@ -557,8 +543,8 @@ declare namespace R { /** * Reports whether two functions have the same value for the specified property. */ - eqProps(prop: string, obj1: T, obj2: U): boolean; - eqProps(prop: string): (obj1: T, obj2: U) => boolean; + eqProps(prop: string, obj1: T, obj2: U): boolean; + eqProps(prop: string): (obj1: T, obj2: U) => boolean; eqProps(prop: string, obj1: T): (obj2: U) => boolean; /** @@ -591,7 +577,6 @@ declare namespace R { find(fn: (a: T) => boolean, list: T[]): T; find(fn: (a: T) => boolean): (list: T[]) => T; - /** * Returns the index of the first element of the list which matches the predicate, or `-1` * if no element matches. @@ -617,16 +602,14 @@ declare namespace R { * Returns a new list by pulling every item out of it (and all its sub-arrays) and putting * them in a new array, depth-first. */ - flatten(x: T[][]): T[]; - flatten(x: T[]): T[]; + flatten(x: T[] | T[][]): T[]; /** * Returns a new function much like the supplied one, except that the first two arguments' * order is reversed. */ - flip(fn: (arg0: T, arg1: U) => TResult): (arg1: U, arg0?: T) => TResult; - flip(fn: (arg0: T, arg1: U, ...args: any[]) => TResult): (arg1: U, arg0?: T, ...args: any[]) => TResult; - + flip(fn: (arg0: T, arg1: U) => TResult): (arg1: U, arg0?: T) => TResult; + flip(fn: (arg0: T, arg1: U, ...args: any[]) => TResult): (arg1: U, arg0?: T, ...args: any[]) => TResult; /** * Iterate over an input list, calling a provided function fn for each element in the list. @@ -637,22 +620,22 @@ declare namespace R { /** * Creates a new object out of a list key-value pairs. */ - fromPairs(pairs: KeyValuePair[]): {[index: string]: V}; - fromPairs(pairs: KeyValuePair[]): {[index: number]: V}; + fromPairs(pairs: Array>): { [index: string]: V }; + fromPairs(pairs: Array>): { [index: number]: V }; /** * Splits a list into sublists stored in an object, based on the result of * calling a String-returning function * on each element, and grouping the results according to values returned. */ - groupBy(fn: (a: T) => string, list: T[]): {[index: string]: T[]} - groupBy(fn: (a: T) => string): (list: T[]) => {[index: string]: T[]} + groupBy(fn: (a: T) => string, list: T[]): { [index: string]: T[] }; + groupBy(fn: (a: T) => string): (list: T[]) => { [index: string]: T[] }; /** * Takes a list and returns a list of lists where each sublist's elements are all "equal" according to the provided equality function */ - groupWith(fn: (x: T, y: T) => boolean, list: T[]): T[][] - groupWith(fn: (x: T, y: T) => boolean, list: string): string[] + groupWith(fn: (x: T, y: T) => boolean, list: T[]): T[][]; + groupWith(fn: (x: T, y: T) => boolean, list: string): string[]; /** * Returns true if the first parameter is greater than the second. @@ -692,7 +675,6 @@ declare namespace R { identical(a: T, b: T): boolean; identical(a: T): (b: T) => boolean; - /** * A function that does nothing but return the parameter supplied to it. Good as a default * or placeholder function. @@ -705,7 +687,6 @@ declare namespace R { */ ifElse(fn: Pred, onTrue: Arity1Fn, onFalse: Arity1Fn): Arity1Fn; - /** * Increments its argument. */ @@ -715,7 +696,7 @@ declare namespace R { * Given a function that generates a key, turns a list of objects into an object indexing the objects * by the given key. */ - indexBy(fn: (a: T) => string, list: T[]): U; + indexBy(fn: (a: T) => string, list: T[]): U; indexBy(fn: (a: T) => string): (list: T[]) => U; /** @@ -748,13 +729,11 @@ declare namespace R { insertAll(index: number, elts: T[]): (list: T[]) => T[]; insertAll(index: number): (elts: T[], list: T[]) => T[]; - /** * Combines two lists into a set (i.e. no duplicates) composed of those elements common to both lists. */ intersection(list1: T[], list2: T[]): T[]; - /** * Combines two lists into a set (i.e. no duplicates) composed of those * elements common to both lists. Duplication is determined according @@ -773,21 +752,19 @@ declare namespace R { * Transforms the items of the list with the transducer and appends the transformed items to the accumulator * using an appropriate iterator function based on the accumulator type. */ - into(acc: any, xf: Function, list: T[]): T[]; - into(acc: any, xf: Function): (list: T[]) => T[]; - into(acc: any): (xf: Function, list: T[]) => T[]; + into(acc: any, xf: (...a: any[]) => any, list: T[]): T[]; + into(acc: any, xf: (...a: any[]) => any): (list: T[]) => T[]; + into(acc: any): (xf: (...a: any[]) => any, list: T[]) => T[]; /** - * Same as R.invertObj, however this accounts for objects with duplicate values by putting the values into an array. - */ - invert(obj: T): {[index:string]: string[]}; + * Same as R.invertObj, however this accounts for objects with duplicate values by putting the values into an array. + */ + invert(obj: T): { [index: string]: string[] }; /** - * Returns a new object with the keys of the given object as values, and the values of the given object as keys. - */ - invertObj(obj: any): {[index:string]: string}; - invertObj(obj: {[index: number]: string}): {[index:string]: string}; - + * Returns a new object with the keys of the given object as values, and the values of the given object as keys. + */ + invertObj(obj: any | { [index: number]: string }): { [index: string]: string }; /** * Turns a named method of an object (or object prototype) into a function that can be @@ -797,8 +774,8 @@ declare namespace R { * The returned function is curried and accepts `len + 1` parameters (or `method.length + 1` * when `len` is not specified), and the final parameter is the target object. */ - invoker(name: string, obj: any, len?: number): Function; - invoker(name: string): (obj: any, len?: number) => Function; + invoker(name: string, obj: any, len?: number): (...a: any[]) => any; + invoker(name: string): (obj: any, len?: number) => (...a: any[]) => any; /** * See if an object (`val`) is an instance of the supplied constructor. @@ -817,7 +794,6 @@ declare namespace R { */ isEmpty(value: any): boolean; - /** * Returns true if the input value is NaN. */ @@ -838,8 +814,7 @@ declare namespace R { /** * Applies a list of functions to a list of values. */ - juxt(fns: {(...args: T[]): U}[]): (...args: T[]) => U[]; - + juxt(fns: Array<(...args: T[]) => U>): (...args: T[]) => U[]; /** * Returns a list containing the names of all the enumerable own @@ -875,7 +850,7 @@ declare namespace R { * "gets" the value of the focus; the setter "sets" the value of the focus. * The setter should not mutate the data structure. */ - lens(getter: (s: T) => U, setter: (a: U, s: T) => V): Lens; + lens(getter: (s: T) => U, setter: (a: U, s: T) => V): Lens; /** * Creates a lens that will focus on index n of the source array. @@ -893,22 +868,21 @@ declare namespace R { */ lensProp(str: string): { (obj: T): U; - set(val: T, obj: U): V; - /*map(fn: Function, obj: T): T*/ - } + set(val: T, obj: U): V; + /*map(fn: (...a: any[]) => any, obj: T): T*/ + }; /** * "lifts" a function of arity > 1 so that it may "map over" a list, Function or other object that satisfies * the FantasyLand Apply spec. */ - lift(fn: Function, ...args: any[]): any; + lift(fn: ((...a: any[]) => any), ...args: any[]): any; /** * "lifts" a function to be the specified arity, so that it may "map over" that many lists, Functions or other * objects that satisfy the FantasyLand Apply spec. */ - liftN(n: number, fn: Function, ...args: any[]): any; - + liftN(n: number, fn: ((...a: any[]) => any), ...args: any[]): any; /** * Returns true if the first parameter is less than the second. @@ -943,12 +917,11 @@ declare namespace R { mapAccumRight(fn: (acc: U, value: T) => [U, TResult]): (acc: U, list: T[]) => [U, TResult[]]; mapAccumRight(fn: (acc: U, value: T) => [U, TResult], acc: U): (list: T[]) => [U, TResult[]]; - /** * Like mapObj, but but passes additional arguments to the predicate function. */ - mapObjIndexed(fn: (value: T, key: string, obj?: any) => TResult, obj: any): {[index:string]: TResult}; - mapObjIndexed(fn: (value: T, key: string, obj?: any) => TResult): (obj: any) => {[index:string]: TResult}; + mapObjIndexed(fn: (value: T, key: string, obj?: any) => TResult, obj: any): { [index: string]: TResult }; + mapObjIndexed(fn: (value: T, key: string, obj?: any) => TResult): (obj: any) => { [index: string]: TResult }; /** * Tests a regular expression agains a String @@ -956,7 +929,6 @@ declare namespace R { match(regexp: RegExp, str: string): any[]; match(regexp: RegExp): (str: string) => any[]; - /** * mathMod behaves like the modulo operator should mathematically, unlike the `%` * operator (and by extension, R.modulo). So while "-17 % 5" is -2, @@ -966,7 +938,6 @@ declare namespace R { mathMod(a: number, b: number): number; mathMod(a: number): (b: number) => number; - /** * Returns the larger of its two arguments. */ @@ -979,7 +950,7 @@ declare namespace R { */ maxBy(keyFn: (a: T) => Ord, a: T, b: T): T; maxBy(keyFn: (a: T) => Ord, a: T): (b: T) => T; - maxBy(keyFn: (a: T) => Ord): CurriedFunction2 + maxBy(keyFn: (a: T) => Ord): CurriedFunction2; /** * Returns the mean of the given list of numbers. @@ -996,7 +967,7 @@ declare namespace R { * returns the result. Subsequent calls to the memoized fn with the same argument set will not result in an * additional call to fn; instead, the cached result for that set of arguments will be returned. */ - memoize(fn: Function): Function; + memoize(fn: (...a: any[]) => any): (...a: any[]) => any; /** * Create a new object with the own properties of a @@ -1006,7 +977,6 @@ declare namespace R { merge(a: T1, b: T2): T1 & T2; merge(a: T1): (b: T2) => T1 & T2; - /** * Merges a list of objects together into one object. */ @@ -1018,9 +988,9 @@ declare namespace R { * the value associated with the key in the returned object. The key will be excluded from the returned object if the * resulting value is undefined. */ - mergeWith(fn: (x: any, z: any) => any, a: U, b: V): U & V; + mergeWith(fn: (x: any, z: any) => any, a: U, b: V): U & V; mergeWith(fn: (x: any, z: any) => any, a: U): (b: V) => U & V; - mergeWith(fn: (x: any, z: any) => any): (a: U, b: V) => U & V; + mergeWith(fn: (x: any, z: any) => any): (a: U, b: V) => U & V; /** * Creates a new object with the own properties of the two provided objects. If a key exists in both objects, @@ -1028,9 +998,9 @@ declare namespace R { * result being used as the value associated with the key in the returned object. The key will be excluded from * the returned object if the resulting value is undefined. */ - mergeWithKey(fn: (str: string, x: any, z: any) => any, a: U, b: V): U & V; + mergeWithKey(fn: (str: string, x: any, z: any) => any, a: U, b: V): U & V; mergeWithKey(fn: (str: string, x: any, z: any) => any, a: U): (b: V) => U & V; - mergeWithKey(fn: (str: string, x: any, z: any) => any): (a: U, b: V) => U & V; + mergeWithKey(fn: (str: string, x: any, z: any) => any): (a: U, b: V) => U & V; /** * Returns the smaller of its two arguments. @@ -1044,7 +1014,7 @@ declare namespace R { */ minBy(keyFn: (a: T) => Ord, a: T, b: T): T; minBy(keyFn: (a: T) => Ord, a: T): (b: T) => T; - minBy(keyFn: (a: T) => Ord): CurriedFunction2 + minBy(keyFn: (a: T) => Ord): CurriedFunction2; /** * Divides the second parameter by the first and returns the remainder. @@ -1061,26 +1031,23 @@ declare namespace R { multiply(a: number, b: number): number; multiply(a: number): (b: number) => number; - /** * Wraps a function of any arity (including nullary) in a function that accepts exactly n parameters. * Any extraneous parameters will not be passed to the supplied function. */ - nAry(n: number, fn: (...arg: any[]) => any): Function; + nAry(n: number, fn: (...arg: any[]) => any): (...a: any[]) => any; /** * Negates its argument. */ negate(n: number): number; - /** * Returns true if no elements of the list match the predicate, false otherwise. */ none(fn: (a: T) => boolean, list: T[]): boolean; none(fn: (a: T) => boolean): (list: T[]) => boolean; - /** * A function wrapping a call to the given function in a `!` operation. It will return `true` when the * underlying function would return a false-y value, and `false` when it would return a truth-y one. @@ -1108,7 +1075,6 @@ declare namespace R { * Returns a singleton array containing the value provided. */ of(x: T): T[]; - //of(x: T[]): T[][]; unnecessary typing and introduced error in unless example /** * Returns a partial copy of an object omitting the keys specified. @@ -1121,18 +1087,17 @@ declare namespace R { * called once, no matter how many times the returned function is invoked. The first value calculated is * returned in subsequent invocations. */ - once(fn: Function): Function; + once(fn: (...a: any[]) => any): (...a: any[]) => any; /** * A function that returns the first truthy of two arguments otherwise the last argument. Note that this is * NOT short-circuited, meaning that if expressions are passed they are both evaluated. * Dispatches to the or method of the first argument if applicable. */ - or(a: T, b: U): T|U; - or(a: T): (b: U) => T|U; - or(fn1: T, val2: U): T|U; - or(fn1: T): (val2: U) => T|U; - + or(a: T, b: U): T | U; + or(a: T): (b: U) => T | U; + or any); }, U>(fn1: T, val2: U): T | U; + or any); }>(fn1: T): (val2: U) => T | U; /** * Returns the result of "setting" the portion of the given data structure @@ -1145,25 +1110,24 @@ declare namespace R { over(lens: Lens): (fn: Arity1Fn, value: T) => T; over(lens: Lens): (fn: Arity1Fn, value: T[]) => T[]; - /** * Takes two arguments, fst and snd, and returns [fst, snd]. */ - pair(fst: F, snd: S): [F, S]; + pair(fst: F, snd: S): [F, S]; /** * Accepts as its arguments a function and any number of values and returns a function that, * when invoked, calls the original function with all of the values prepended to the * original function's arguments list. In some libraries this function is named `applyLeft`. */ - partial(fn: Function, ...args: any[]): Function; + partial(fn: (...a: any[]) => any, ...args: any[]): (...a: any[]) => any; /** * Accepts as its arguments a function and any number of values and returns a function that, * when invoked, calls the original function with all of the values appended to the original * function's arguments list. */ - partialRight(fn: Function, ...args: any[]): Function; + partialRight(fn: (...a: any[]) => any, ...args: any[]): (...a: any[]) => any; /** * Takes a predicate and a list and returns the pair of lists of elements @@ -1181,9 +1145,9 @@ declare namespace R { path(path: Path): (obj: any) => T; /** - * Determines whether a nested path on an object has a specific value, - * in `R.equals` terms. Most likely used to filter a list. - */ + * Determines whether a nested path on an object has a specific value, + * in `R.equals` terms. Most likely used to filter a list. + */ pathEq(path: Path, val: any, obj: any): boolean; pathEq(path: Path, val: any): (obj: any) => boolean; pathEq(path: Path): CurriedFunction2; @@ -1192,38 +1156,35 @@ declare namespace R { * If the given, non-null object has a value at the given path, returns the value at that path. * Otherwise returns the provided default value. */ - pathOr(d: T, p: Path, obj: any): T|any; - pathOr(d: T, p: Path): (obj: any) => T|any; - pathOr(d: T): CurriedFunction2; + pathOr(d: T, p: Path, obj: any): T | any; + pathOr(d: T, p: Path): (obj: any) => T | any; + pathOr(d: T): CurriedFunction2; /** * Returns true if the specified object property satisfies the given predicate; false otherwise. */ - pathSatisfies(pred: (val: T) => boolean, path: Path, obj: U): boolean; - pathSatisfies(pred: (val: T) => boolean, path: Path): (obj: U) => boolean; - pathSatisfies(pred: (val: T) => boolean): CurriedFunction2; + pathSatisfies(pred: (val: T) => boolean, path: Path, obj: U): boolean; + pathSatisfies(pred: (val: T) => boolean, path: Path): (obj: U) => boolean; + pathSatisfies(pred: (val: T) => boolean): CurriedFunction2; /** * Returns a partial copy of an object containing only the keys specified. If the key does not exist, the * property is ignored. */ - pick(names: string[], obj: T): U; + pick(names: string[], obj: T): U; pick(names: string[]): (obj: T) => U; - /** * Similar to `pick` except that this one includes a `key: undefined` pair for properties that don't exist. */ - pickAll(names: string[], obj: T): U; - pickAll(names: string[]): (obj: T) => U; - + pickAll(names: string[], obj: T): U; + pickAll(names: string[]): (obj: T) => U; /** * Returns a partial copy of an object containing only the keys that satisfy the supplied predicate. */ - pickBy(pred: ObjPred, obj: T): U; - pickBy(pred: ObjPred): (obj: T) => U; - + pickBy(pred: ObjPred, obj: T): U; + pickBy(pred: ObjPred): (obj: T) => U; /** * Creates a new function that runs each of the functions supplied as parameters in turn, @@ -1252,22 +1213,65 @@ declare namespace R { pipe(fn0: (x: V0) => T1, fn1: (x: T1) => T2, fn2: (x: T2) => T3, fn3: (x: T3) => T4, fn4: (x: T4) => T5, fn5: (x: T5) => T6): (x: V0) => T6; pipe(fn0: (x0: V0, x1: V1) => T1, fn1: (x: T1) => T2, fn2: (x: T2) => T3, fn3: (x: T3) => T4, fn4: (x: T4) => T5, fn5: (x: T5) => T6): (x0: V0, x1: V1) => T6; - pipe(fn0: (x0: V0, x1: V1, x2: V2) => T1, fn1: (x: T1) => T2, fn2: (x: T2) => T3, fn3: (x: T3) => T4, fn4: (x: T4) => T5, fn5: (x: T5) => T6): (x0: V0, x1: V1, x2: V2) => T6; + pipe(fn0: (x0: V0, x1: V1, x2: V2) => T1, + fn1: (x: T1) => T2, + fn2: (x: T2) => T3, + fn3: (x: T3) => T4, + fn4: (x: T4) => T5, + fn5: (x: T5) => T6): (x0: V0, x1: V1, x2: V2) => T6; - pipe(fn0: (x: V0) => T1, fn1: (x: T1) => T2, fn2: (x: T2) => T3, fn3: (x: T3) => T4, fn4: (x: T4) => T5, fn5: (x: T5) => T6, fn: (x: T6) => T7): (x: V0) => T7; - pipe(fn0: (x0: V0, x1: V1) => T1, fn1: (x: T1) => T2, fn2: (x: T2) => T3, fn3: (x: T3) => T4, fn4: (x: T4) => T5, fn5: (x: T5) => T6, fn6: (x: T6) => T7): (x0: V0, x1: V1) => T7; - pipe(fn0: (x0: V0, x1: V1, x2: V2) => T1, fn1: (x: T1) => T2, fn2: (x: T2) => T3, fn3: (x: T3) => T4, fn4: (x: T4) => T5, fn5: (x: T5) => T6, fn6: (x: T6) => T7): (x0: V0, x1: V1, x2: V2) => T7; - - pipe(fn0: (x: V0) => T1, fn1: (x: T1) => T2, fn2: (x: T2) => T3, fn3: (x: T3) => T4, fn4: (x: T4) => T5, fn5: (x: T5) => T6, fn6: (x: T6) => T7, fn: (x: T7) => T8): (x: V0) => T8; - pipe(fn0: (x0: V0, x1: V1) => T1, fn1: (x: T1) => T2, fn2: (x: T2) => T3, fn3: (x: T3) => T4, fn4: (x: T4) => T5, fn5: (x: T5) => T6, fn6: (x: T5) => T6, fn7: (x: T7) => T8): (x0: V0, x1: V1) => T8; - pipe(fn0: (x0: V0, x1: V1, x2: V2) => T1, fn1: (x: T1) => T2, fn2: (x: T2) => T3, fn3: (x: T3) => T4, fn4: (x: T4) => T5, fn5: (x: T5) => T6, fn6: (x: T5) => T6, fn7: (x: T7) => T8): (x0: V0, x1: V1, x2: V2) => T8; + pipe(fn0: (x: V0) => T1, + fn1: (x: T1) => T2, + fn2: (x: T2) => T3, + fn3: (x: T3) => T4, + fn4: (x: T4) => T5, + fn5: (x: T5) => T6, + fn: (x: T6) => T7): (x: V0) => T7; + pipe(fn0: (x0: V0, x1: V1) => T1, + fn1: (x: T1) => T2, + fn2: (x: T2) => T3, + fn3: (x: T3) => T4, + fn4: (x: T4) => T5, + fn5: (x: T5) => T6, + fn6: (x: T6) => T7): (x0: V0, x1: V1) => T7; + pipe(fn0: (x0: V0, x1: V1, x2: V2) => T1, + fn1: (x: T1) => T2, + fn2: (x: T2) => T3, + fn3: (x: T3) => T4, + fn4: (x: T4) => T5, + fn5: (x: T5) => T6, + fn6: (x: T6) => T7): (x0: V0, x1: V1, x2: V2) => T7; + pipe(fn0: (x: V0) => T1, + fn1: (x: T1) => T2, + fn2: (x: T2) => T3, + fn3: (x: T3) => T4, + fn4: (x: T4) => T5, + fn5: (x: T5) => T6, + fn6: (x: T6) => T7, + fn: (x: T7) => T8): (x: V0) => T8; + pipe(fn0: (x0: V0, x1: V1) => T1, + fn1: (x: T1) => T2, + fn2: (x: T2) => T3, + fn3: (x: T3) => T4, + fn4: (x: T4) => T5, + fn5: (x: T5) => T6, + fn6: (x: T5) => T6, + fn7: (x: T7) => T8): (x0: V0, x1: V1) => T8; + pipe(fn0: (x0: V0, x1: V1, x2: V2) => T1, + fn1: (x: T1) => T2, + fn2: (x: T2) => T3, + fn3: (x: T3) => T4, + fn4: (x: T4) => T5, + fn5: (x: T5) => T6, + fn6: (x: T5) => T6, + fn7: (x: T7) => T8): (x0: V0, x1: V1, x2: V2) => T8; /** * Returns a new list by plucking the same named property off all objects in the list supplied. */ - pluck(p: string|number, list: any[]): T[]; - pluck(p: string|number): (list: any[]) => T[]; + pluck(p: string | number, list: any[]): T[]; + pluck(p: string | number): (list: any[]) => T[]; /** * Returns a new list with the given element at the front, followed by the contents of the @@ -1281,11 +1285,10 @@ declare namespace R { */ product(list: number[]): number; - /** * Reasonable analog to SQL `select` statement. */ - project(props: string[], objs: T[]): U[]; + project(props: string[], objs: T[]): U[]; /** * Returns a function that when supplied an object returns the indicated property of that object, if it exists. @@ -1316,15 +1319,15 @@ declare namespace R { propIs(type: any): { (name: string, obj: any): boolean; (name: string): (obj: any) => boolean; - } + }; /** * If the given, non-null object has an own property with the specified name, returns the value of that property. * Otherwise returns the provided default value. */ - propOr(val: T, p: string, obj: U): V; - propOr(val: T, p: string): (obj: U) => V; - propOr(val: T): (p: string, obj: U) => V; + propOr(val: T, p: string, obj: U): V; + propOr(val: T, p: string): (obj: U) => V; + propOr(val: T): (p: string, obj: U) => V; /** * Returns the value at the specified property. @@ -1337,9 +1340,9 @@ declare namespace R { /** * Returns true if the specified object property satisfies the given predicate; false otherwise. */ - propSatisfies(pred: (val: T) => boolean, name: string, obj: U): boolean; - propSatisfies(pred: (val: T) => boolean, name: string): (obj: U) => boolean; - propSatisfies(pred: (val: T) => boolean): CurriedFunction2; + propSatisfies(pred: (val: T) => boolean, name: string, obj: U): boolean; + propSatisfies(pred: (val: T) => boolean, name: string): (obj: U) => boolean; + propSatisfies(pred: (val: T) => boolean): CurriedFunction2; /** * Returns a list of numbers from `from` (inclusive) to `to` @@ -1354,18 +1357,18 @@ declare namespace R { * function and passing it an accumulator value and the current value from the array, and * then passing the result to the next call. */ - reduce(fn: (acc: TResult, elem: T) => TResult|Reduced, acc: TResult, list: T[]): TResult; - reduce(fn: (acc: TResult, elem: T) => TResult|Reduced): (acc: TResult, list: T[]) => TResult; - reduce(fn: (acc: TResult, elem: T) => TResult|Reduced, acc: TResult): (list: T[]) => TResult; + reduce(fn: (acc: TResult, elem: T) => TResult | Reduced, acc: TResult, list: T[]): TResult; + reduce(fn: (acc: TResult, elem: T) => TResult | Reduced): (acc: TResult, list: T[]) => TResult; + reduce(fn: (acc: TResult, elem: T) => TResult | Reduced, acc: TResult): (list: T[]) => TResult; /** * Groups the elements of the list according to the result of calling the String-returning function keyFn on each * element and reduces the elements of each group to a single value via the reducer function valueFn. */ - reduceBy(valueFn: (acc: TResult, elem: T) => TResult, acc: TResult, keyFn: (elem: T) => string, list: T[]): {[index: string]: TResult}; - reduceBy(valueFn: (acc: TResult, elem: T) => TResult, acc: TResult, keyFn: (elem: T) => string): (list: T[]) => {[index: string]: TResult}; - reduceBy(valueFn: (acc: TResult, elem: T) => TResult, acc: TResult): CurriedFunction2<(elem: T) => string, T[], {[index: string]: TResult}>; - reduceBy(valueFn: (acc: TResult, elem: T) => TResult): CurriedFunction3 string, T[], {[index: string]: TResult}>; + reduceBy(valueFn: (acc: TResult, elem: T) => TResult, acc: TResult, keyFn: (elem: T) => string, list: T[]): { [index: string]: TResult }; + reduceBy(valueFn: (acc: TResult, elem: T) => TResult, acc: TResult, keyFn: (elem: T) => string): (list: T[]) => { [index: string]: TResult }; + reduceBy(valueFn: (acc: TResult, elem: T) => TResult, acc: TResult): CurriedFunction2<(elem: T) => string, T[], { [index: string]: TResult }>; + reduceBy(valueFn: (acc: TResult, elem: T) => TResult): CurriedFunction3 string, T[], { [index: string]: TResult }>; /** * Returns a value wrapped to indicate that it is the final value of the reduce and @@ -1403,17 +1406,12 @@ declare namespace R { repeat(a: T, n: number): T[]; repeat(a: T): (n: number) => T[]; - /** * Replace a substring or regex match in a string with a replacement. */ - replace(pattern: RegExp, replacement: string, str: string): string; - replace(pattern: RegExp, replacement: string): (str: string) => string; - replace(pattern: RegExp): (replacement: string) => (str: string) => string; - replace(pattern: String, replacement: string, str: string): string; - replace(pattern: String, replacement: string): (str: string) => string; - replace(pattern: String): (replacement: string) => (str: string) => string; - + replace(pattern: RegExp | string, replacement: string, str: string): string; + replace(pattern: RegExp | string, replacement: string): (str: string) => string; + replace(pattern: RegExp | string): (replacement: string) => (str: string) => string; /** * Returns a new list with the same elements as the original list, just in the reverse order. @@ -1431,17 +1429,17 @@ declare namespace R { * Returns the result of "setting" the portion of the given data structure focused by the given lens to the * given value. */ - set(lens: Lens, a: U, obj: T): T; + set(lens: Lens, a: U, obj: T): T; set(lens: Lens, a: U): (obj: T) => T; - set(lens: Lens): (a: U, obj: T) => T; + set(lens: Lens): (a: U, obj: T) => T; /** * Returns the elements from `xs` starting at `a` and ending at `b - 1`. */ slice(a: number, b: number, list: string): string; slice(a: number, b: number, list: T[]): T[]; - slice(a: number, b: number): (list: string|T[]) => string|T[]; - slice(a: number): (b: number, list: string|T[]) => string|T[]; + slice(a: number, b: number): (list: string | T[]) => string | T[]; + slice(a: number): (b: number, list: string | T[]) => string | T[]; /** * Returns a copy of the list, sorted according to the comparator function, which should accept two values at a @@ -1451,7 +1449,6 @@ declare namespace R { sort(fn: (a: T, b: T) => number, list: T[]): T[]; sort(fn: (a: T, b: T) => number): (list: T[]) => T[]; - /** * Sorts the list according to a key generated by the supplied function. */ @@ -1462,10 +1459,8 @@ declare namespace R { * Splits a string into an array of strings based on the given * separator. */ - split(sep: string): (str: string) => string[]; - split(sep: RegExp): (str: string) => string[]; - split(sep: string, str: string): string[]; - split(sep: RegExp, str: string): string[]; + split(sep: string | RegExp): (str: string) => string[]; + split(sep: string | RegExp, str: string): string[]; /** * Splits a given list or string at a given index. @@ -1481,14 +1476,13 @@ declare namespace R { splitEvery(a: number, list: T[]): T[][]; splitEvery(a: number): (list: T[]) => T[][]; - /** * Takes a list and a predicate and returns a pair of lists with the following properties: * - the result of concatenating the two output lists is equivalent to the input list; * - none of the elements of the first output list satisfies the predicate; and * - if the second output list is non-empty, its first element satisfies the predicate. */ - splitWhen(pred: (val: T) => boolean, list: U[]): U[][]; + splitWhen(pred: (val: T) => boolean, list: U[]): U[][]; splitWhen(pred: (val: T) => boolean): (list: U[]) => U[][]; /** @@ -1535,8 +1529,7 @@ declare namespace R { take(n: number): { (xs: string): string; (xs: T[]): T[]; - } - + }; /** * Returns a new list containing the last n elements of the given list. If n > list.length, @@ -1547,7 +1540,7 @@ declare namespace R { takeLast(n: number): { (xs: T[]): T[]; (xs: string): string; - } + }; /** * Returns a new list containing the last n elements of a given list, passing each value @@ -1555,8 +1548,8 @@ declare namespace R { * false. Excludes the element that caused the predicate function to fail. The predicate * function is passed one argument: (value). */ - takeLastWhile(pred: (a: T) => Boolean, list: T[]): T[]; - takeLastWhile(pred: (a: T) => Boolean): (list: T[]) => T[]; + takeLastWhile(pred: (a: T) => boolean, list: T[]): T[]; + takeLastWhile(pred: (a: T) => boolean): (list: T[]) => T[]; /** * Returns a new list containing the first `n` elements of a given list, passing each value @@ -1585,7 +1578,6 @@ declare namespace R { times(fn: (i: number) => T, n: number): T[]; times(fn: (i: number) => T): (n: number) => T[]; - /** * The lower case version of a string. */ @@ -1597,7 +1589,7 @@ declare namespace R { * Note that the order of the output array is not guaranteed to be * consistent across different JS platforms. */ - toPairs(obj: {[k: string]: S} | {[k: number]: S} | any): [F,S][]; + toPairs(obj: { [k: string]: S } | { [k: number]: S } | any): Array<[F, S]>; /** * Converts an object into an array of key, value arrays. @@ -1605,7 +1597,7 @@ declare namespace R { * Note that the order of the output array is not guaranteed to be * consistent across different JS platforms. */ - toPairsIn(obj: {[k: string]: S} | {[k: number]: S} | any): [F,S][]; + toPairsIn(obj: { [k: string]: S } | { [k: number]: S } | any): Array<[F, S]>; /** * Returns the string representation of the given value. eval'ing the output should @@ -1629,10 +1621,10 @@ declare namespace R { * list, successively calling the transformed iterator function and passing it an accumulator value and the * current value from the array, and then passing the result to the next call. */ - transduce(xf: (arg: T[]) => T[], fn: (acc: U[], val: U) => U[], acc: T[], list: T[]): U; - transduce(xf: (arg: T[]) => T[]): (fn: (acc: U[], val: U) => U[], acc: T[], list: T[]) => U; - transduce(xf: (arg: T[]) => T[], fn: (acc: U[], val: U) => U[]): (acc: T[], list: T[]) => U; - transduce(xf: (arg: T[]) => T[], fn: (acc: U[], val: U) => U[], acc: T[]): (list: T[]) => U; + transduce(xf: (arg: T[]) => T[], fn: (acc: U[], val: U) => U[], acc: T[], list: T[]): U; + transduce(xf: (arg: T[]) => T[]): (fn: (acc: U[], val: U) => U[], acc: T[], list: T[]) => U; + transduce(xf: (arg: T[]) => T[], fn: (acc: U[], val: U) => U[]): (acc: T[], list: T[]) => U; + transduce(xf: (arg: T[]) => T[], fn: (acc: U[], val: U) => U[], acc: T[]): (list: T[]) => U; /** * Transposes the rows and columns of a 2D list. When passed a list of n lists of length x, returns a list of x lists of length n. @@ -1673,7 +1665,7 @@ declare namespace R { * Wraps a function of any arity (including nullary) in a function that accepts exactly 1 parameter. * Any extraneous parameters will not be passed to the supplied function. */ - unary(fn: (a: T, ...args: any[]) => any): (a: T) => any + unary(fn: (a: T, ...args: any[]) => any): (a: T) => any; /** * Returns a function of arity n from a (manually) curried function. @@ -1685,8 +1677,8 @@ declare namespace R { * to stop iteration or an array of length 2 containing the value to add to the resulting * list and the seed to be used in the next call to the iterator function. */ - unfold(fn: (seed: T) => TResult[]|boolean, seed: T): TResult[]; - unfold(fn: (seed: T) => TResult[]|boolean): (seed: T) => TResult[]; + unfold(fn: (seed: T) => TResult[] | boolean, seed: T): TResult[]; + unfold(fn: (seed: T) => TResult[] | boolean): (seed: T) => TResult[]; /** * Combines two lists into a set (i.e. no duplicates) composed of the @@ -1700,7 +1692,7 @@ declare namespace R { * determined according to the value returned by applying the supplied predicate to two list elements. */ unionWith(pred: (a: T, b: T) => boolean, list1: T[], list2: T[]): T[]; - unionWith(pred: (a: T, b: T) => boolean): CurriedFunction2 + unionWith(pred: (a: T, b: T) => boolean): CurriedFunction2; /** * Returns a new list containing only one copy of each element in the original list. @@ -1708,40 +1700,42 @@ declare namespace R { uniq(list: T[]): T[]; /** - * Returns a new list containing only one copy of each element in the original list, based upon the value returned by applying the supplied function to each list element. Prefers the first item if the supplied function produces the same value on two items. R.equals is used for comparison. + * Returns a new list containing only one copy of each element in the original list, + * based upon the value returned by applying the supplied function to each list element. + * Prefers the first item if the supplied function produces the same value on two items. + * R.equals is used for comparison. */ - uniqBy(fn: (a: T) => U, list: T[]): T[]; - uniqBy(fn: (a: T) => U): (list: T[]) => T[]; + uniqBy(fn: (a: T) => U, list: T[]): T[]; + uniqBy(fn: (a: T) => U): (list: T[]) => T[]; /** * Returns a new list containing only one copy of each element in the original list, based upon the value * returned by applying the supplied predicate to two list elements. */ - uniqWith(pred: (x: T, y: T) => boolean, list: T[]): T[]; - uniqWith(pred: (x: T, y: T) => boolean): (list: T[]) => T[]; + uniqWith(pred: (x: T, y: T) => boolean, list: T[]): T[]; + uniqWith(pred: (x: T, y: T) => boolean): (list: T[]) => T[]; /** * Tests the final argument by passing it to the given predicate function. If the predicate is not satisfied, * the function will return the result of calling the whenFalseFn function with the same argument. If the * predicate is satisfied, the argument is returned as is. */ - unless(pred: (a: T) => boolean, whenFalseFn: (a: T) => U, obj: T): U; - unless(pred: (a: T) => boolean, whenFalseFn: (a: T) => U): (obj: T) => U; + unless(pred: (a: T) => boolean, whenFalseFn: (a: T) => U, obj: T): U; + unless(pred: (a: T) => boolean, whenFalseFn: (a: T) => U): (obj: T) => U; /** * Returns a new list by pulling every item at the first level of nesting out, and putting * them in a new array. */ - unnest(x: T[][]): T[]; - unnest(x: T[]): T[]; + unnest(x: T[][] | T[]): T[]; /** * Takes a predicate, a transformation function, and an initial value, and returns a value of the same type as * the initial value. It does so by applying the transformation until the predicate is satisfied, at which point * it returns the satisfactory value. */ - until(pred: (val: T) => boolean, fn: (val: T) => U, init: U): U; - until(pred: (val: T) => boolean, fn: (val: T) => U): (init: U) => U; + until(pred: (val: T) => boolean, fn: (val: T) => U, init: U): U; + until(pred: (val: T) => boolean, fn: (val: T) => U): (init: U) => U; /** * Returns a new copy of the array with the element at the provided index replaced with the given value. @@ -1759,15 +1753,14 @@ declare namespace R { * need to be transformed, although you can ignore them, it's best to pass an identity function so * that the new function reports the correct arity. */ - useWith(fn: Function, transformers: Function[]): Function; + useWith(fn: ((...a: any[]) => any), transformers: Array<((...a: any[]) => any)>): (...a: any[]) => any; /** * Returns a list of all the enumerable own properties of the supplied object. * Note that the order of the output array is not guaranteed across * different JS platforms. */ - values(obj: {[index: string]: T}): T[]; - values(obj: any): T[]; + values(obj: { [index: string]: T } | any): T[]; /** * Returns a list of all the properties, including prototype properties, of the supplied @@ -1779,16 +1772,16 @@ declare namespace R { * Returns a "view" of the given data structure, determined by the given lens. The lens's focus determines which * portion of the data structure is visible. */ - view(lens: Lens): (obj: T) => U; - view(lens: Lens, obj: T): U; + view(lens: Lens): (obj: T) => U; + view(lens: Lens, obj: T): U; /** * Tests the final argument by passing it to the given predicate function. If the predicate is satisfied, the function * will return the result of calling the whenTrueFn function with the same argument. If the predicate is not satisfied, * the argument is returned as is. */ - when(pred: (a: T) => boolean, whenTrueFn: (a: T) => U, obj: T): U; - when(pred: (a: T) => boolean, whenTrueFn: (a: T) => U): (obj: T) => U; + when(pred: (a: T) => boolean, whenTrueFn: (a: T) => U, obj: T): U; + when(pred: (a: T) => boolean, whenTrueFn: (a: T) => U): (obj: T) => U; /** * Takes a spec object and a test object and returns true if the test satisfies the spec. @@ -1801,18 +1794,18 @@ declare namespace R { * `where` is well suited to declarativley expressing constraints for other functions, e.g., * `filter`, `find`, `pickWith`, etc. */ - where(spec: T, testObj: U): boolean; + where(spec: T, testObj: U): boolean; where(spec: T): (testObj: U) => boolean; - where(spec: ObjFunc2, testObj: U): boolean; + where(spec: ObjFunc2, testObj: U): boolean; where(spec: ObjFunc2): (testObj: U) => boolean; - /** - * Takes a spec object and a test object; returns true if the test satisfies the spec, - * false otherwise. An object satisfies the spec if, for each of the spec's own properties, - * accessing that property of the object gives the same value (in R.eq terms) as accessing - * that property of the spec. - */ - whereEq(spec: T, obj: U): boolean; + /** + * Takes a spec object and a test object; returns true if the test satisfies the spec, + * false otherwise. An object satisfies the spec if, for each of the spec's own properties, + * accessing that property of the object gives the same value (in R.eq terms) as accessing + * that property of the spec. + */ + whereEq(spec: T, obj: U): boolean; whereEq(spec: T): (obj: U) => boolean; /** @@ -1826,28 +1819,27 @@ declare namespace R { * Wrap a function inside another to allow you to make adjustments to the parameters, or do other processing * either before the internal function is called or with its results. */ - wrap(fn: Function, wrapper: Function): Function; + wrap(fn: (...a: any[]) => any, wrapper: (...a: any[]) => any): (...a: any[]) => any; /** * Creates a new list out of the two supplied by creating each possible pair from the lists. */ - xprod(as: K[], bs: V[]): KeyValuePair[]; - xprod(as: K[]): (bs: V[]) => KeyValuePair[]; + xprod(as: K[], bs: V[]): Array>; + xprod(as: K[]): (bs: V[]) => Array>; /** * Creates a new list out of the two supplied by pairing up equally-positioned items from * both lists. Note: `zip` is equivalent to `zipWith(function(a, b) { return [a, b] })`. */ - zip(list1: K[], list2: V[]): KeyValuePair[]; - zip(list1: K[]): (list2: V[]) => KeyValuePair[]; + zip(list1: K[], list2: V[]): Array>; + zip(list1: K[]): (list2: V[]) => Array>; /** * Creates a new object out of a list of keys and a list of values. */ // TODO: Dictionary as a return value is to specific, any seems to loose - zipObj(keys: string[], values: T[]): {[index:string]: T}; - zipObj(keys: string[]): (values: T[]) => {[index:string]: T}; - + zipObj(keys: string[], values: T[]): { [index: string]: T }; + zipObj(keys: string[]): (values: T[]) => { [index: string]: T }; /** * Creates a new list out of the two supplied by applying the function to each @@ -1856,7 +1848,6 @@ declare namespace R { zipWith(fn: (x: T, y: U) => TResult, list1: T[], list2: U[]): TResult[]; zipWith(fn: (x: T, y: U) => TResult, list1: T[]): (list2: U[]) => TResult[]; zipWith(fn: (x: T, y: U) => TResult): (list1: T[], list2: U[]) => TResult[]; - } } diff --git a/types/ramda/ramda-tests.ts b/types/ramda/ramda-tests.ts index a5f28e0559..706774f12f 100644 --- a/types/ramda/ramda-tests.ts +++ b/types/ramda/ramda-tests.ts @@ -1,2043 +1,2200 @@ -import * as R from 'ramda'; +import * as R from "ramda"; -var double = function(x: number): number { - return x + x -}; +function double(x: number): number { + return x + x; +} -var shout = function(x: number): string { - return x >= 10 - ? 'big' - : 'small' -}; +function shout(x: number): string { + return x >= 10 ? "big" : "small"; +} class F { - x = 'X'; - y = 'Y'; + x = "X"; + y = "Y"; } class F2 { a = 100; y = 1; - x(){}; - z() {}; + + x() { + } + + z() { + } } (() => { - var x: boolean; - x = R.isArrayLike('a'); - x = R.isArrayLike([1,2,3]); + let x: boolean; + x = R.isArrayLike("a"); + x = R.isArrayLike([1, 2, 3]); x = R.isArrayLike([]); }); (() => { - R.propIs(Number, 'x', {x: 1, y: 2}); //=> true - R.propIs(Number, 'x')({x: 1, y: 2}); //=> true - R.propIs(Number)('x', {x: 1, y: 2}); //=> true - R.propIs(Number)('x')({x: 1, y: 2}); //=> true - R.propIs(Number, 'x', {x: 'foo'}); //=> false - R.propIs(Number, 'x', {}); //=> false + R.propIs(Number, "x", {x: 1, y: 2}); // => true + R.propIs(Number, "x")({x: 1, y: 2}); // => true + R.propIs(Number)("x", {x: 1, y: 2}); // => true + R.propIs(Number)("x")({x: 1, y: 2}); // => true + R.propIs(Number, "x", {x: "foo"}); // => false + R.propIs(Number, "x", {}); // => false }); (() => { - R.type({}); //=> "Object" - R.type(1); //=> "Number" - R.type(false); //=> "Boolean" - R.type('s'); //=> "String" - R.type(null); //=> "Null" - R.type([]); //=> "Array" - R.type(/[A-z]/); //=> "RegExp" + R.type({}); // => "Object" + R.type(1); // => "Number" + R.type(false); // => "Boolean" + R.type("s"); // => "String" + R.type(null); // => "Null" + R.type([]); // => "Array" + R.type(/[A-z]/); // => "RegExp" }); () => { - var takesNoArg = function() { return true; }; - var takesOneArg = function(a: number) { return [a]; }; - var takesTwoArgs = function(a: number, b: number) { return [a, b]; }; - var takesThreeArgs = function(a: number, b: number, c: number) { return [a, b, c]; }; + function takesNoArg() { + return true; + } + function takesOneArg(a: number) { + return [a]; + } + function takesTwoArgs(a: number, b: number) { + return [a, b]; + } + function takesThreeArgs(a: number, b: number, c: number) { + return [a, b, c]; + } - var addFourNumbers = function(a: number, b: number, c: number, d: number): number { - return a + b + c + d; - }; + function addFourNumbers(a: number, b: number, c: number, d: number): number { + return a + b + c + d; + } - var x1: Function = R.curry(addFourNumbers) + let x1: (a: number, b: number, c: number, d: number) => number = R.curry(addFourNumbers); // because of the current way of currying, the following call results in a type error - // var x2: Function = R.curry(addFourNumbers)(1,2,4) - var x3: Function = R.curry(addFourNumbers)(1)(2) - var x4: Function = R.curry(addFourNumbers)(1)(2)(3) - var y1: number = R.curry(addFourNumbers)(1)(2)(3)(4) - var y2: number = R.curry(addFourNumbers)(1,2)(3,4) - var y3: number = R.curry(addFourNumbers)(1,2,3)(4) + // let x2: Function = R.curry(addFourNumbers)(1,2,4) + let x3: (c: number, d: number) => number = R.curry(addFourNumbers)(1)(2); + let x4: (d: number) => number = R.curry(addFourNumbers)(1)(2)(3); + let y1: number = R.curry(addFourNumbers)(1)(2)(3)(4); + let y2: number = R.curry(addFourNumbers)(1, 2)(3, 4); + let y3: number = R.curry(addFourNumbers)(1, 2, 3)(4); R.nAry(0, takesNoArg); R.nAry(0, takesOneArg); R.nAry(1, takesTwoArgs); R.nAry(1, takesThreeArgs); - var u1: {(a: any): any} = R.unary(takesOneArg); - var u2: {(a: any): any} = R.unary(takesTwoArgs); - var u3: {(a: any): any} = R.unary(takesThreeArgs); + let u1: (a: any) => any = R.unary(takesOneArg); + let u2: (a: any) => any = R.unary(takesTwoArgs); + let u3: (a: any) => any = R.unary(takesThreeArgs); R.binary(takesTwoArgs); R.binary(takesThreeArgs); - var addTwoNumbers = function(a:number, b:number) { return a + b; } - var addTwoNumbersCurried = R.curry(addTwoNumbers); + function addTwoNumbers(a: number, b: number) { + return a + b; + } - var inc = addTwoNumbersCurried(1); - var z1:number = inc(2); - var z2:number = addTwoNumbersCurried(2,3); -} + let addTwoNumbersCurried = R.curry(addTwoNumbers); + + let inc = addTwoNumbersCurried(1); + let z1: number = inc(2); + let z2: number = addTwoNumbersCurried(2, 3); +}; () => { - interface Car { speed?: number; } - interface FastCar { speed: number; } - - const typeGuard = function(a: number, b: number, c: number, d: number, e: number, car: Car): car is FastCar { - return car.speed !== undefined; + interface Car { speed?: number; } + interface FastCar { speed: number; + } + + function typeGuard(a: number, b: number, c: number, d: number, e: number, car: Car): car is FastCar { + return car.speed !== undefined; + } + const typeGuardCurried = R.curry(typeGuard); - const drive = function(fastCar: FastCar) {}; - - const cars: Car[] = [{ speed: 65 }, {}]; - for (const car of cars) { - if (typeGuardCurried(1)(2)(3)(4)(5)(car)) { - drive(car); - } + function drive(fastCar: FastCar) { } -} + + const cars: Car[] = [{speed: 65}, {}]; + for (const car of cars) { + if (typeGuardCurried(1)(2)(3)(4)(5)(car)) { + drive(car); + } + } +}; () => { - const addFour = (a:number) => (b:number) => (c:number) => (d:number) => a + b + c + d; + const addFour = (a: number) => (b: number) => (c: number) => (d: number) => a + b + c + d; const uncurriedAddFour = R.uncurryN(4, addFour); - const res: number = uncurriedAddFour(1, 2, 3, 4); //=> 10 -} + const res: number = uncurriedAddFour(1, 2, 3, 4); // => 10 +}; () => { // coerceArray :: (a|[a]) -> [a] const coerceArray = R.unless(R.isArrayLike, R.of); - const a: number[] = coerceArray([1, 2, 3]); //=> [1, 2, 3] - const b: number[] = coerceArray(1); //=> [1] -} + const a: number[] = coerceArray([1, 2, 3]); // => [1, 2, 3] + const b: number[] = coerceArray(1); // => [1] +}; (() => { - R.nthArg(1)('a', 'b', 'c'); //=> 'b' - R.nthArg(-1)('a', 'b', 'c'); //=> 'c' + R.nthArg(1)("a", "b", "c"); // => 'b' + R.nthArg(-1)("a", "b", "c"); // => 'c' }); () => { - const fn: (...args: string[])=>string = R.unapply(JSON.stringify); - const res: string = R.unapply(JSON.stringify)(1, 2, 3); //=> '[1,2,3]' -} + const fn: (...args: string[]) => string = R.unapply(JSON.stringify); + const res: string = R.unapply(JSON.stringify)(1, 2, 3); // => '[1,2,3]' +}; () => { - const a: number = R.until(R.flip(R.gt)(100), R.multiply(2))(1) // => 128 -} + const a: number = R.until(R.flip(R.gt)(100), R.multiply(2))(1); // => 128 +}; () => { - const truncate = R.when( - R.propSatisfies(R.flip(R.gt)(10), 'length'), - R.pipe(R.take(10), R.append('…'), R.join('')) + const truncate = R.when( + R.propSatisfies(R.flip(R.gt)(10), "length"), + R.pipe(R.take(10), R.append("…"), R.join("")) ); - const a: string = truncate('12345'); //=> '12345' - const b: string = truncate('0123456789ABC'); //=> '0123456789…' -} + const a: string = truncate("12345"); // => '12345' + const b: string = truncate("0123456789ABC"); // => '0123456789…' +}; /* compose */ () => { - var double = function(x: number): number { - return x + x + function double(x: number): number { + return x + x; } - var limit10 = function(x: number): boolean { - return x >= 10 + + function limit10(x: number): boolean { + return x >= 10; } - var func: (x: number) => boolean = R.compose(limit10, double) - var res: boolean = R.compose(limit10, double)(10) + + let func: (x: number) => boolean = R.compose(limit10, double); + let res: boolean = R.compose(limit10, double)(10); const f0 = (s: string) => +s; // string -> number const f1 = (n: number) => n === 1; // number -> boolean const f2 = R.compose(f1, f0); // string -> boolean // akward example that bounces types between number and string - const g0 = (list: number[]) => R.map(R.inc, list); - const g1 = R.dropWhile(R.gt(10)); - const g2 = R.map((i: number) => i > 5 ? 'bigger' : 'smaller'); - const g3 = R.all((i: string) => i === 'smaller'); - const g = R.compose(g3, g2, g1, g0); + const g0 = (list: number[]) => R.map(R.inc, list); + const g1 = R.dropWhile(R.gt(10)); + const g2 = R.map((i: number) => i > 5 ? "bigger" : "smaller"); + const g3 = R.all((i: string) => i === "smaller"); + const g = R.compose(g3, g2, g1, g0); const g_res: boolean = g([1, 2, 10, 13]); -} +}; /* pipe */ () => { - var func: (x: number) => string = R.pipe(double, double, shout) - var res: string = R.pipe(double, double, shout)(10); + let func: (x: number) => string = R.pipe(double, double, shout); + let res: string = R.pipe(double, double, shout)(10); const capitalize = (str: string) => R.pipe( - R.split(''), + R.split(""), R.adjust(R.toUpper, 0), - R.join('') + R.join("") )(str); - var f = R.pipe(Math.pow, R.negate, R.inc); - var fr: number = f(3, 4); // -(3^4) + 1 -} + let f = R.pipe(Math.pow, R.negate, R.inc); + let fr: number = f(3, 4); // -(3^4) + 1 +}; () => { - R.invoker('charAt', String.prototype); - R.invoker('charAt', String.prototype, 1); -} + R.invoker("charAt", String.prototype); + R.invoker("charAt", String.prototype, 1); +}; (() => { const range = R.juxt([Math.min, Math.max]); - range(3, 4, 9, -3); //=> [-3, 9] + range(3, 4, 9, -3); // => [-3, 9] const chopped = R.juxt([R.head, R.last]); - chopped('longstring'); // => ["l", "g"] + chopped("longstring"); // => ["l", "g"] }); -var square = function(x: number) { return x * x; }; -var add = function(a: number, b: number) { return a + b; }; +function square(x: number) { + return x * x; +} +function add(a: number, b: number) { + return a + b; +} // Adds any number of arguments together -var addAll = function() { - return 0; -}; +function addAll() { + return 0; +} // Basic example -R.useWith(addAll, [ double, square ]); +R.useWith(addAll, [double, square]); (() => { - var printXPlusFive = function(x: number) { console.log(x + 5); }; - R.forEach(printXPlusFive, [1, 2, 3]); - R.clone([{},{},{}]) - R.clone([1,2,3]); + function printXPlusFive(x: number) { + console.log(x + 5); + } + + R.forEach(printXPlusFive, [1, 2, 3]); + R.clone([{}, {}, {}]); + R.clone([1, 2, 3]); })(); // (() => { -// var printXPlusFive = function(x, i) { console.log(i + 5); }; +// function printXPlusFive(x, i) { console.log(i + 5); } // R.forEach.idx(printXPlusFive, [{name: 1}, {name: 2}, {name: 3}]); // })(); -var i = function(x: number) {return x;}; +function i(x: number) { + return x; +} R.times(i, 5); (() => { - var triple = function(x: number): number { return x * 3; }; - var square = function(x: number): number { return x * x; }; - var squareThenDoubleThenTriple = R.pipe(square, double, triple); - squareThenDoubleThenTriple(5); //=> 150 + function triple(x: number): number { + return x * 3; + } + function square(x: number): number { + return x * x; + } + let squareThenDoubleThenTriple = R.pipe(square, double, triple); + squareThenDoubleThenTriple(5); // => 150 })(); (() => { - var multiply = function(a: number, b: number) { return a * b; }; - var double = R.partial(multiply, 2); - double(2); //=> 4 + function multiply(a: number, b: number) { + return a * b; + } - var greet = function(salutation: string, title: string, firstName: string, lastName: string) { - return salutation + ', ' + title + ' ' + firstName + ' ' + lastName + '!'; - }; - var sayHello = R.partial(greet, 'Hello'); - var sayHelloToMs = R.partial(sayHello, 'Ms.'); - sayHelloToMs('Jane', 'Jones'); //=> 'Hello, Ms. Jane Jones!' + let double = R.partial(multiply, 2); + double(2); // => 4 - var greetMsJaneJones = R.partialRight(greet, 'Ms.', 'Jane', 'Jones'); - greetMsJaneJones('Hello'); //=> 'Hello, Ms. Jane Jones!' + function greet(salutation: string, title: string, firstName: string, lastName: string) { + return salutation + ", " + title + " " + firstName + " " + lastName + "!"; + } + + let sayHello = R.partial(greet, "Hello"); + let sayHelloToMs = R.partial(sayHello, "Ms."); + sayHelloToMs("Jane", "Jones"); // => 'Hello, Ms. Jane Jones!' + + let greetMsJaneJones = R.partialRight(greet, "Ms.", "Jane", "Jones"); + greetMsJaneJones("Hello"); // => 'Hello, Ms. Jane Jones!' })(); (() => { - var numberOfCalls = 0; - var trackedAdd = function(a: number, b: number) { - numberOfCalls += 1; - return a + b; - }; - var memoTrackedAdd = R.memoize(trackedAdd); + let numberOfCalls = 0; - memoTrackedAdd(1, 2); //=> 3 - numberOfCalls; //=> 1 - memoTrackedAdd(1, 2); //=> 3 - numberOfCalls; //=> 1 - memoTrackedAdd(2, 3); //=> 5 - numberOfCalls; //=> 2 + function trackedAdd(a: number, b: number) { + numberOfCalls += 1; + return a + b; + } + + let memoTrackedAdd = R.memoize(trackedAdd); + + memoTrackedAdd(1, 2); // => 3 + numberOfCalls; // => 1 + memoTrackedAdd(1, 2); // => 3 + numberOfCalls; // => 1 + memoTrackedAdd(2, 3); // => 5 + numberOfCalls; // => 2 // Note that argument order matters - memoTrackedAdd(2, 1); //=> 3 - numberOfCalls; //=> 3 + memoTrackedAdd(2, 1); // => 3 + numberOfCalls; // => 3 })(); (() => { - var addOneOnce = R.once(function(x: number){ return x + 1; }); - addOneOnce(10); //=> 11 - addOneOnce(addOneOnce(50)); //=> 11 + let addOneOnce = R.once((x: number) => x + 1); + addOneOnce(10); // => 11 + addOneOnce(addOneOnce(50)); // => 11 })(); (() => { - var slashify = R.wrap(R.flip(R.add)('/'), function(f: Function, x: string) { - return R.match(/\/$/, x) ? x : f(x); - }); + let slashify = R.wrap(R.flip(R.add)("/"), (f: (x: string) => string, x: string) => R.match(/\/$/, x) ? x : f(x)); - slashify('a'); //=> 'a/' - slashify('a/'); //=> 'a/' -})(); - - - -(() => { - var numbers = [1, 2, 3]; - var add = function(a: number, b: number) { - return a + b - }; - R.reduce(add, 10, numbers); //=> 16; + slashify("a"); // => 'a/' + slashify("a/"); // => 'a/' })(); (() => { - var plus3 = R.add(3); + let numbers = [1, 2, 3]; + let add = (a: number, b: number) => a + b; + R.reduce(add, 10, numbers); // => 16; })(); (() => { - var pairs = [ ['a', 1], ['b', 2], ['c', 3] ]; - var flattenPairs = function(acc: [string, number], pair: [string, number]) { - return acc.concat(pair); - }; - R.reduceRight(flattenPairs, [], pairs); //=> [ 'c', 3, 'b', 2, 'a', 1 ] + let plus3 = R.add(3); })(); (() => { - var values = { x: 1, y: 2, z: 3 }; - var prependKeyAndDouble = function(num: number, key: string, obj: any) { + let pairs = [["a", 1], ["b", 2], ["c", 3]]; + + function flattenPairs(acc: [string, number], pair: [string, number]) { + return acc.concat(pair); + } + + R.reduceRight(flattenPairs, [], pairs); // => [ 'c', 3, 'b', 2, 'a', 1 ] +})(); + +(() => { + let values = {x: 1, y: 2, z: 3}; + + function prependKeyAndDouble(num: number, key: string, obj: any) { return key + (num * 2); - }; - R.mapObjIndexed(prependKeyAndDouble, values); //=> { x: 'x2', y: 'y4', z: 'z6' } + } + + R.mapObjIndexed(prependKeyAndDouble, values); // => { x: 'x2', y: 'y4', z: 'z6' } }); (() => { - const a: number[] = R.ap([R.multiply(2), R.add(3)], [1,2,3]); //=> [2, 4, 6, 4, 5, 6] - const b: number[][] = R.of([1]); //=> [[1]] - const c: number[] = R.of(1); - + const a: number[] = R.ap([R.multiply(2), R.add(3)], [1, 2, 3]); // => [2, 4, 6, 4, 5, 6] + const b: number[][] = R.of([1]); // => [[1]] + const c: number[] = R.of(1); }); () => { - const a1 = R.empty([1,2,3,4,5]); //=> [] - const a2 = R.empty([1, 2, 3]); //=> [] - const a3 = R.empty('unicorns'); //=> '' - const a4 = R.empty({x: 1, y: 2}); //=> {} -} + const a1 = R.empty([1, 2, 3, 4, 5]); // => [] + const a2 = R.empty([1, 2, 3]); // => [] + const a3 = R.empty("unicorns"); // => '' + const a4 = R.empty({x: 1, y: 2}); // => {} +}; (() => { - R.length([1, 2, 3]); //=> 3 + R.length([1, 2, 3]); // => 3 }); (() => { - const isEven = function(n: number) { + function isEven(n: number) { return n % 2 === 0; - }; + } + const filterIndexed = R.addIndex(R.filter); - R.filter(isEven, [1, 2, 3, 4]); //=> [2, 4] + R.filter(isEven, [1, 2, 3, 4]); // => [2, 4] - var lastTwo = function(val: number, idx: number, list: number[]) { - return list.length - idx <= 2; - }; - filterIndexed(lastTwo, [8, 6, 7, 5, 3, 0, 9]); //=> [0, 9] + function lastTwo(val: number, idx: number, list: number[]) { + return list.length - idx <= 2; + } - var isOdd = function(n: number) { - return n % 2 === 1; - }; - R.reject(isOdd, [1, 2, 3, 4]); //=> [2, 4] + filterIndexed(lastTwo, [8, 6, 7, 5, 3, 0, 9]); // => [0, 9] + + function isOdd(n: number) { + return n % 2 === 1; + } + + R.reject(isOdd, [1, 2, 3, 4]); // => [2, 4] }); (() => { - var isNotFour = function(x: number) { - return !(x === 4); - }; - R.takeWhile(isNotFour, [1, 2, 3, 4]); //=> [1, 2, 3] - R.take(2, [1, 2, 3, 4]); //=> [1, 2] + function isNotFour(x: number) { + return !(x === 4); + } + + R.takeWhile(isNotFour, [1, 2, 3, 4]); // => [1, 2, 3] + R.take(2, [1, 2, 3, 4]); // => [1, 2] }); (() => { - var f = function(n: number) { return n > 50 ? false : [-n, n + 10] }; - let a = R.unfold(f, 10); //=> [-10, -20, -30, -40, -50] - let b = R.unfold(f); //=> [-10, -20, -30, -40, -50] + function f(n: number) { + return n > 50 ? false : [-n, n + 10]; + } + + let a = R.unfold(f, 10); // => [-10, -20, -30, -40, -50] + let b = R.unfold(f); // => [-10, -20, -30, -40, -50] let c = b(10); }); /***************************************************************** * Function category */ +() => { + function mergeThree(a: number, b: number, c: number): number[] { + return ([]).concat(a, b, c); + } - - () => { - var mergeThree = function(a: number, b: number, c: number): number[] { - return ([]).concat(a, b, c); - }; - mergeThree(1, 2, 3); //=> [1, 2, 3] - var flipped = R.flip(mergeThree); - flipped(1, 2, 3); //=> [2, 1, 3] - } + mergeThree(1, 2, 3); // => [1, 2, 3] + let flipped = R.flip(mergeThree); + flipped(1, 2, 3); // => [2, 1, 3] +}; /********************* * List category ********************/ () => { - var lessThan2 = R.flip(R.lt)(2); - var lessThan3 = R.flip(R.lt)(3); - R.all(lessThan2)([1, 2]); //=> false - R.all(lessThan3)([1, 2]); //=> true -} + let lessThan2 = R.flip(R.lt)(2); + let lessThan3 = R.flip(R.lt)(3); + R.all(lessThan2)([1, 2]); // => false + R.all(lessThan3)([1, 2]); // => true +}; () => { - var lessThan0 = R.flip(R.lt)(0); - var lessThan2 = R.flip(R.lt)(2); - R.any(lessThan0)([1, 2]); //=> false - R.any(lessThan2)([1, 2]); //=> true -} + let lessThan0 = R.flip(R.lt)(0); + let lessThan2 = R.flip(R.lt)(2); + R.any(lessThan0)([1, 2]); // => false + R.any(lessThan2)([1, 2]); // => true +}; () => { - R.aperture(2, [1, 2, 3, 4, 5]); //=> [[1, 2], [2, 3], [3, 4], [4, 5]] - R.aperture(3, [1, 2, 3, 4, 5]); //=> [[1, 2, 3], [2, 3, 4], [3, 4, 5]] - R.aperture(7, [1, 2, 3, 4, 5]); //=> [] - R.aperture(7)([1, 2, 3, 4, 5]); //=> [] -} + R.aperture(2, [1, 2, 3, 4, 5]); // => [[1, 2], [2, 3], [3, 4], [4, 5]] + R.aperture(3, [1, 2, 3, 4, 5]); // => [[1, 2, 3], [2, 3, 4], [3, 4, 5]] + R.aperture(7, [1, 2, 3, 4, 5]); // => [] + R.aperture(7)([1, 2, 3, 4, 5]); // => [] +}; () => { - R.append('tests', ['write', 'more']); //=> ['write', 'more', 'tests'] - R.append('tests')(['write', 'more']); //=> ['write', 'more', 'tests'] - R.append('tests', []); //=> ['tests'] - R.append(['tests'], ['write', 'more']); //=> ['write', 'more', ['tests']] - R.append(['tests'], ['write', 'more']); //=> ['write', 'more', ['tests']] - R.append(['tests'])(['write', 'more']); //=> ['write', 'more', ['tests']] - R.append(['tests'])(['write', 'more']); //=> ['write', 'more', ['tests']] -} + R.append("tests", ["write", "more"]); // => ['write', 'more', 'tests'] + R.append("tests")(["write", "more"]); // => ['write', 'more', 'tests'] + R.append("tests", []); // => ['tests'] + R.append(["tests"], ["write", "more"]); // => ['write', 'more', ['tests']] + R.append(["tests"], ["write", "more"]); // => ['write', 'more', ['tests']] + R.append(["tests"])(["write", "more"]); // => ['write', 'more', ['tests']] + R.append(["tests"])(["write", "more"]); // => ['write', 'more', ['tests']] +}; () => { - var duplicate = function(n: number) { + function duplicate(n: number) { return [n, n]; - }; - R.chain(duplicate, [1, 2, 3]); //=> [1, 1, 2, 2, 3, 3] - R.chain(duplicate)([1, 2, 3]); //=> [1, 1, 2, 2, 3, 3] -} + } + + R.chain(duplicate, [1, 2, 3]); // => [1, 1, 2, 2, 3, 3] + R.chain(duplicate)([1, 2, 3]); // => [1, 1, 2, 2, 3, 3] +}; () => { - R.clamp(1, 10, -1) // => 1 - R.clamp(1, 10)(11) // => 10 - R.clamp(1)(10, 4) // => 4 - R.clamp('a', 'd', 'e') // => 'd' -} + R.clamp(1, 10, -1); // => 1 + R.clamp(1, 10)(11); // => 10 + R.clamp(1)(10, 4); // => 4 + R.clamp("a", "d", "e"); // => 'd' +}; () => { - R.concat([], []); //=> [] - R.concat([4, 5, 6], [1, 2, 3]); //=> [4, 5, 6, 1, 2, 3] - R.concat([4, 5, 6])([1, 2, 3]); //=> [4, 5, 6, 1, 2, 3] - R.concat('ABC')('DEF'); // 'ABCDEF' -} + R.concat([], []); // => [] + R.concat([4, 5, 6], [1, 2, 3]); // => [4, 5, 6, 1, 2, 3] + R.concat([4, 5, 6])([1, 2, 3]); // => [4, 5, 6, 1, 2, 3] + R.concat("ABC")("DEF"); // 'ABCDEF' +}; () => { - R.contains(3)([1, 2, 3]); //=> true - R.contains(3, [1, 2, 3]); //=> true - R.contains(4)([1, 2, 3]); //=> false - R.contains({})([{}, {}]); //=> false - var obj = {}; - R.contains(obj)([{}, obj, {}]); //=> true -} + R.contains(3)([1, 2, 3]); // => true + R.contains(3, [1, 2, 3]); // => true + R.contains(4)([1, 2, 3]); // => false + R.contains({})([{}, {}]); // => false + let obj = {}; + R.contains(obj)([{}, obj, {}]); // => true +}; () => { - R.drop(3, [1,2,3,4,5,6,7]); //=> [4,5,6,7] - R.drop(3)([1,2,3,4,5,6,7]); //=> [4,5,6,7] - R.drop(3, 'ramda'); //=> 'ram' - R.drop(3)('ramda'); //=> 'ram' -} + R.drop(3, [1, 2, 3, 4, 5, 6, 7]); // => [4,5,6,7] + R.drop(3)([1, 2, 3, 4, 5, 6, 7]); // => [4,5,6,7] + R.drop(3, "ramda"); // => 'ram' + R.drop(3)("ramda"); // => 'ram' +}; (() => { - R.dropLast(1, ['foo', 'bar', 'baz']); //=> ['foo', 'bar'] - R.dropLast(2)(['foo', 'bar', 'baz']); //=> ['foo'] - R.dropLast(3, 'ramda'); //=> 'ra' - R.dropLast(3)('ramda'); //=> 'ra' + R.dropLast(1, ["foo", "bar", "baz"]); // => ['foo', 'bar'] + R.dropLast(2)(["foo", "bar", "baz"]); // => ['foo'] + R.dropLast(3, "ramda"); // => 'ra' + R.dropLast(3)("ramda"); // => 'ra' }); (() => { - var lteThree = (x: number) => x <= 3; - R.dropLastWhile(lteThree, [1, 2, 3, 4, 3, 2, 1]); //=> [1, 2, 3, 4] + let lteThree = (x: number) => x <= 3; + R.dropLastWhile(lteThree, [1, 2, 3, 4, 3, 2, 1]); // => [1, 2, 3, 4] }); () => { - var lteTwo = function(x: number) { + function lteTwo(x: number) { return x <= 2; - }; - R.dropWhile(lteTwo, [1, 2, 3, 4]); //=> [3, 4] - R.dropWhile(lteTwo)([1, 2, 3, 4]); //=> [3, 4] -} + } + + R.dropWhile(lteTwo, [1, 2, 3, 4]); // => [3, 4] + R.dropWhile(lteTwo)([1, 2, 3, 4]); // => [3, 4] +}; () => { - var isEven = function(n: number) { + function isEven(n: number) { return n % 2 === 0; - }; - R.filter(isEven, [1, 2, 3, 4]); //=> [2, 4] - var isEvenFn = R.filter(isEven); + } + R.filter(isEven, [1, 2, 3, 4]); // => [2, 4] + let isEvenFn = R.filter(isEven); isEvenFn([1, 2, 3, 4]); -} +}; () => { - var lastTwo = function(val: number, idx: number, list: number[]) { + function lastTwo(val: number, idx: number, list: number[]) { return list.length - idx <= 2; - }; - var filterIndexed = R.addIndex(R.filter); + } - filterIndexed(lastTwo, [8, 6, 7, 5, 3, 0, 9]); //=> [0, 9] - var lastTwoFn = filterIndexed(lastTwo); + let filterIndexed = R.addIndex(R.filter); + + filterIndexed(lastTwo, [8, 6, 7, 5, 3, 0, 9]); // => [0, 9] + let lastTwoFn = filterIndexed(lastTwo); lastTwoFn([8, 6, 7, 5, 3, 0, 9]); -} +}; () => { - var xs = [{a: 1}, {a: 2}, {a: 3}]; - R.find(R.propEq('a', 2))(xs); //=> {a: 2} - R.find(R.propEq('a', 4))(xs); //=> undefined -} + let xs = [{a: 1}, {a: 2}, {a: 3}]; + R.find(R.propEq("a", 2))(xs); // => {a: 2} + R.find(R.propEq("a", 4))(xs); // => undefined +}; () => { - var xs = [{a: 1}, {a: 2}, {a: 3}]; - R.findIndex(R.propEq('a', 2))(xs); //=> 1 - R.findIndex(R.propEq('a', 4))(xs); //=> -1 + let xs = [{a: 1}, {a: 2}, {a: 3}]; + R.findIndex(R.propEq("a", 2))(xs); // => 1 + R.findIndex(R.propEq("a", 4))(xs); // => -1 R.findIndex((x: number) => x === 1, [1, 2, 3]); -} +}; () => { - var xs = [{a: 1, b: 0}, {a:1, b: 1}]; - R.findLast(R.propEq('a', 1))(xs); //=> {a: 1, b: 1} - R.findLast(R.propEq('a', 4))(xs); //=> undefined -} + let xs = [{a: 1, b: 0}, {a: 1, b: 1}]; + R.findLast(R.propEq("a", 1))(xs); // => {a: 1, b: 1} + R.findLast(R.propEq("a", 4))(xs); // => undefined +}; () => { - var xs = [{a: 1, b: 0}, {a:1, b: 1}]; - R.findLastIndex(R.propEq('a', 1))(xs); //=> 1 - R.findLastIndex(R.propEq('a', 4))(xs); //=> -1 + let xs = [{a: 1, b: 0}, {a: 1, b: 1}]; + R.findLastIndex(R.propEq("a", 1))(xs); // => 1 + R.findLastIndex(R.propEq("a", 4))(xs); // => -1 R.findLastIndex((x: number) => x === 1, [1, 2, 3]); -} +}; + () => { - const testPath = ['x', 0, 'y']; - const testObj = {x: [{y: 2, z: 3}, {y: 4, z: 5}]}; + const testPath = ["x", 0, "y"]; + const testObj = {x: [{y: 2, z: 3}, {y: 4, z: 5}]}; R.pathEq(testPath, 2, testObj); // => true R.pathEq(testPath, 2)(testObj); // => true R.pathEq(testPath)(2)(testObj); // => true R.pathEq(testPath)(2, testObj); // => true - var user1 = { address: { zipCode: 90210 } }; - var user2 = { address: { zipCode: 55555 } }; - var user3 = { name: 'Bob' }; - var users = [ user1, user2, user3 ]; - var isFamous = R.pathEq(['address', 'zipCode'], 90210); - R.filter(isFamous, users); //=> [ user1 ] -} + let user1 = {address: {zipCode: 90210}}; + let user2 = {address: {zipCode: 55555}}; + let user3 = {name: "Bob"}; + let users = [user1, user2, user3]; + let isFamous = R.pathEq(["address", "zipCode"], 90210); + R.filter(isFamous, users); // => [ user1 ] +}; + () => { - var xs: {[key:string]: string} = {a: '1', b: '0'}; - R.propEq('a', '1', xs);//=> true - R.propEq('a', '4', xs); //=> false -} + let xs: { [key: string]: string } = {a: "1", b: "0"}; + R.propEq("a", "1", xs); // => true + R.propEq("a", "4", xs); // => false +}; + () => { - var xs: {[key:string]: number} = {a: 1, b: 0}; - R.propEq('a', 1, xs);//=> true - R.propEq('a', 4, xs); //=> false -} + let xs: { [key: string]: number } = {a: 1, b: 0}; + R.propEq("a", 1, xs); // => true + R.propEq("a", 4, xs); // => false +}; + () => { - var xs = {a: '1', b: '0'}; - R.propEq('a', '1', xs);//=> true - R.propEq('a', '4', xs); //=> false -} + let xs = {a: "1", b: "0"}; + R.propEq("a", "1", xs); // => true + R.propEq("a", "4", xs); // => false +}; + () => { - var xs = {a: 1, b: 0}; - R.propEq('a', 1, xs);//=> true - R.propEq('a', 4, xs); //=> false + let xs = {a: 1, b: 0}; + R.propEq("a", 1, xs); // => true + R.propEq("a", 4, xs); // => false +}; + +interface Obj { + a: number; + b: number; } -interface Obj { a: number; b: number }; () => { - var xs: Obj = {a: 1, b: 0}; - R.propEq('a', 1, xs);//=> true - R.propEq('a', 4, xs); //=> false -} + let xs: Obj = {a: 1, b: 0}; + R.propEq("a", 1, xs); // => true + R.propEq("a", 4, xs); // => false +}; () => { R.flatten([1, 2, [3, 4], 5, [6, [7, 8, [9, [10, 11], 12]]]]); - //=> [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12] -} + // => [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12] +}; () => { - var printXPlusFive = function(x: number) { console.log(x + 5); }; - R.forEach(printXPlusFive, [1, 2, 3]); //=> [1, 2, 3] - R.forEach(printXPlusFive)([1, 2, 3]); //=> [1, 2, 3] - //-> 6 - //-> 7 - //-> 8 -} + function printXPlusFive(x: number) { + console.log(x + 5); + } + + R.forEach(printXPlusFive, [1, 2, 3]); // => [1, 2, 3] + R.forEach(printXPlusFive)([1, 2, 3]); // => [1, 2, 3] + // -> 6 + // -> 7 + // -> 8 +}; () => { - var plusFive = function(num: number, idx: number, list: number[]) { list[idx] = num + 5 }; - R.addIndex(R.forEach)(plusFive)([1, 2, 3]); //=> [6, 7, 8] -} + function plusFive(num: number, idx: number, list: number[]) { + list[idx] = num + 5; + } + + R.addIndex(R.forEach)(plusFive)([1, 2, 3]); // => [6, 7, 8] +}; () => { - var byGrade = R.groupBy(function(student: {score: number; name: string}) { - var score = student.score; - return score < 65 ? 'F' : - score < 70 ? 'D' : - score < 80 ? 'C' : - score < 90 ? 'B' : 'A'; + let byGrade = R.groupBy((student: { score: number; name: string }) => { + let score = student.score; + return score < 65 ? "F" : + score < 70 ? "D" : + score < 80 ? "C" : + score < 90 ? "B" : "A"; }); - var students = [{name: 'Abby', score: 84}, - {name: 'Eddy', score: 58}, - {name: 'Jack', score: 69}]; + let students = [{name: "Abby", score: 84}, + {name: "Eddy", score: 58}, + {name: "Jack", score: 69}]; byGrade(students); -} +}; () => { - R.groupWith(R.equals, [0, 1, 1, 2, 3, 5, 8, 13, 21]) + R.groupWith(R.equals, [0, 1, 1, 2, 3, 5, 8, 13, 21]); // [[0], [1, 1], [2, 3, 5, 8, 13, 21]] - R.groupWith((a: number, b: number) => a % 2 === b % 2, [0, 1, 1, 2, 3, 5, 8, 13, 21]) + R.groupWith((a: number, b: number) => a % 2 === b % 2, [0, 1, 1, 2, 3, 5, 8, 13, 21]); // [[0], [1, 1], [2], [3, 5], [8], [13, 21]] - const isVowel = (a: string) => R.contains(a, 'aeiou') ? a : ''; - R.groupWith(R.eqBy(isVowel), 'aestiou') + const isVowel = (a: string) => R.contains(a, "aeiou") ? a : ""; + R.groupWith(R.eqBy(isVowel), "aestiou"); // ['ae', 'st', 'iou'] -} +}; () => { - R.head(['fi', 'fo', 'fum']); //=> 'fi' - R.head([10, 'ten']); // => 10 - R.head(['10', 10]); // => '10' - R.head('abc'); //=> 'a' - R.head(''); //=> '' -} + R.head(["fi", "fo", "fum"]); // => 'fi' + R.head([10, "ten"]); // => 10 + R.head(["10", 10]); // => '10' + R.head("abc"); // => 'a' + R.head(""); // => '' +}; (() => { - let list = [{id: 'xyz', title: 'A'}, {id: 'abc', title: 'B'}]; - const a1 = R.indexBy(R.prop('id'), list); - const a2 = R.indexBy(R.prop('id'))(list); - const a3 = R.indexBy<{id:string}>(R.prop('id'))(list); + let list = [{id: "xyz", title: "A"}, {id: "abc", title: "B"}]; + const a1 = R.indexBy(R.prop("id"), list); + const a2 = R.indexBy(R.prop("id"))(list); + const a3 = R.indexBy<{ id: string }>(R.prop("id"))(list); }); () => { - R.indexOf(3, [1,2,3,4]); //=> 2 - R.indexOf(10)([1,2,3,4]); //=> -1 -} + R.indexOf(3, [1, 2, 3, 4]); // => 2 + R.indexOf(10)([1, 2, 3, 4]); // => -1 +}; () => { - R.init(['fi', 'fo', 'fum']); //=> ['fi', 'fo'] - R.init('abc'); //=> 'ab' - R.init(''); //=> '' -} + R.init(["fi", "fo", "fum"]); // => ['fi', 'fo'] + R.init("abc"); // => 'ab' + R.init(""); // => '' +}; () => { - R.insert(2, 5, [1,2,3,4]); //=> [1,2,5,3,4] - R.insert(2)(5, [1,2,3,4]); //=> [1,2,5,3,4] - R.insert(2, 5)([1,2,3,4]); //=> [1,2,5,3,4] -} + R.insert(2, 5, [1, 2, 3, 4]); // => [1,2,5,3,4] + R.insert(2)(5, [1, 2, 3, 4]); // => [1,2,5,3,4] + R.insert(2, 5)([1, 2, 3, 4]); // => [1,2,5,3,4] +}; () => { - R.insertAll(2, [10,11,12], [1,2,3,4]); - R.insertAll(2)([10,11,12], [1,2,3,4]); - R.insertAll(2, [10,11,12])([1,2,3,4]); -} + R.insertAll(2, [10, 11, 12], [1, 2, 3, 4]); + R.insertAll(2)([10, 11, 12], [1, 2, 3, 4]); + R.insertAll(2, [10, 11, 12])([1, 2, 3, 4]); +}; () => { - var numbers = [1, 2, 3, 4]; - var transducer = R.compose(R.map(R.add(1)), R.take(2)); + let numbers = [1, 2, 3, 4]; + let transducer = R.compose(R.map(R.add(1)), R.take(2)); - R.into([], transducer, numbers); //=> [2, 3] + R.into([], transducer, numbers); // => [2, 3] - var intoArray = R.into([]); - intoArray(transducer, numbers); //=> [2, 3] -} + let intoArray = R.into([]); + intoArray(transducer, numbers); // => [2, 3] +}; () => { - var spacer = R.join(' '); - spacer(['a', 2, 3.4]); //=> 'a 2 3.4' - R.join('|', [1, 2, 3]); //=> '1|2|3' -} + let spacer = R.join(" "); + spacer(["a", 2, 3.4]); // => 'a 2 3.4' + R.join("|", [1, 2, 3]); // => '1|2|3' +}; () => { - R.last(['fi', 'fo', 'fum']); //=> 'fum' - R.last('abc'); //=> 'c' - R.last(''); //=> '' -} + R.last(["fi", "fo", "fum"]); // => 'fum' + R.last("abc"); // => 'c' + R.last(""); // => '' +}; () => { - R.lastIndexOf(3, [-1,3,3,0,1,2,3,4]); //=> 6 - R.lastIndexOf(10, [1,2,3,4]); //=> -1 -} + R.lastIndexOf(3, [-1, 3, 3, 0, 1, 2, 3, 4]); // => 6 + R.lastIndexOf(10, [1, 2, 3, 4]); // => -1 +}; () => { - R.length([]); //=> 0 - R.length([1, 2, 3]); //=> 3 -} + R.length([]); // => 0 + R.length([1, 2, 3]); // => 3 +}; () => { - var headLens = R.lensIndex(0); - headLens([10, 20, 30, 40]); //=> 10 - headLens.set('mu', [10, 20, 30, 40]); //=> ['mu', 20, 30, 40] - R.view(headLens, ['a', 'b', 'c']); //=> 'a' - R.set(headLens, 'x', ['a', 'b', 'c']); //=> ['x', 'b', 'c'] - R.over(headLens, R.toUpper, ['a', 'b', 'c']); //=> ['A', 'b', 'c'] -} + let headLens = R.lensIndex(0); + headLens([10, 20, 30, 40]); // => 10 + headLens.set("mu", [10, 20, 30, 40]); // => ['mu', 20, 30, 40] + R.view(headLens, ["a", "b", "c"]); // => 'a' + R.set(headLens, "x", ["a", "b", "c"]); // => ['x', 'b', 'c'] + R.over(headLens, R.toUpper, ["a", "b", "c"]); // => ['A', 'b', 'c'] +}; () => { - var double = function(x: number) { + function double(x: number) { return x * 2; - }; - R.map(double, [1, 2, 3]); //=> [2, 4, 6] + } + + R.map(double, [1, 2, 3]); // => [2, 4, 6] // functor const stringFunctor = { map: (fn: (c: number) => number) => { - var chars = "Ifmmp!Xpsme".split(""); + let chars = "Ifmmp!Xpsme".split(""); return chars.map((char) => String.fromCharCode(fn(char.charCodeAt(0)))).join("") as any; } }; - R.map((x: number) => x-1, stringFunctor); // => "Hello World" -} + R.map((x: number) => x - 1, stringFunctor); // => "Hello World" +}; () => { - var digits = ['1', '2', '3', '4']; - var append = function(a: string, b: string): [string, string]{ - return [a + b, a + b]; - } - R.mapAccum(append, '0', digits); //=> ['01234', ['01', '012', '0123', '01234']] - R.mapAccum(append)('0', digits); //=> ['01234', ['01', '012', '0123', '01234']] - R.mapAccum(append, '0')(digits); //=> ['01234', ['01', '012', '0123', '01234']] -} + let digits = ["1", "2", "3", "4"]; -() => { - var digits = ['1', '2', '3', '4']; - var append = function(a: string, b: string): [string, string] { + function append(a: string, b: string): [string, string] { return [a + b, a + b]; } - R.mapAccumRight(append, '0', digits); //=> ['04321', ['04321', '0432', '043', '04']] - R.mapAccumRight(append)('0', digits); //=> ['04321', ['04321', '0432', '043', '04']] - R.mapAccumRight(append, '0')(digits); //=> ['04321', ['04321', '0432', '043', '04']] -} + R.mapAccum(append, "0", digits); // => ['01234', ['01', '012', '0123', '01234']] + R.mapAccum(append)("0", digits); // => ['01234', ['01', '012', '0123', '01234']] + R.mapAccum(append, "0")(digits); // => ['01234', ['01', '012', '0123', '01234']] +}; () => { - var squareEnds = function(elt: number, idx: number, list: number[]) { + let digits = ["1", "2", "3", "4"]; + + function append(a: string, b: string): [string, string] { + return [a + b, a + b]; + } + + R.mapAccumRight(append, "0", digits); // => ['04321', ['04321', '0432', '043', '04']] + R.mapAccumRight(append)("0", digits); // => ['04321', ['04321', '0432', '043', '04']] + R.mapAccumRight(append, "0")(digits); // => ['04321', ['04321', '0432', '043', '04']] +}; + +() => { + function squareEnds(elt: number, idx: number, list: number[]) { if (idx === 0 || idx === list.length - 1) { return elt * elt; } return elt; - }; - R.addIndex(R.map)(squareEnds, [8, 5, 3, 0, 9]); //=> [64, 5, 3, 0, 81] - R.addIndex(R.map)(squareEnds)([8, 5, 3, 0, 9]); //=> [64, 5, 3, 0, 81] -} + } + + R.addIndex(R.map)(squareEnds, [8, 5, 3, 0, 9]); // => [64, 5, 3, 0, 81] + R.addIndex(R.map)(squareEnds)([8, 5, 3, 0, 9]); // => [64, 5, 3, 0, 81] +}; () => { - R.none(R.isNaN, [1, 2, 3]); //=> true - R.none(R.isNaN, [1, 2, 3, NaN]); //=> false - R.none(R.isNaN)([1, 2, 3, NaN]); //=> false -} + R.none(R.isNaN, [1, 2, 3]); // => true + R.none(R.isNaN, [1, 2, 3, NaN]); // => false + R.none(R.isNaN)([1, 2, 3, NaN]); // => false +}; () => { - var list = ['foo', 'bar', 'baz', 'quux']; - R.nth(1, list); //=> 'bar' - R.nth(-1, list); //=> 'quux' - R.nth(-99, list); //=> undefined - R.nth(-99)(list); //=> undefined -} + let list = ["foo", "bar", "baz", "quux"]; + R.nth(1, list); // => 'bar' + R.nth(-1, list); // => 'quux' + R.nth(-99, list); // => undefined + R.nth(-99)(list); // => undefined +}; () => { - R.partition(R.contains('s'), ['sss', 'ttt', 'foo', 'bars']); - R.partition(R.contains('s'))(['sss', 'ttt', 'foo', 'bars']); + R.partition(R.contains("s"), ["sss", "ttt", "foo", "bars"]); + R.partition(R.contains("s"))(["sss", "ttt", "foo", "bars"]); R.partition((x: number) => x > 2, [1, 2, 3, 4]); R.partition((x: number) => x > 2)([1, 2, 3, 4]); -} +}; () => { - const a = R.pluck('a')([{a: 1}, {a: 2}]); //=> [1, 2] - const b = R.pluck(0)([[1, 2], [3, 4]]); //=> [1, 3] -} + const a = R.pluck("a")([{a: 1}, {a: 2}]); // => [1, 2] + const b = R.pluck(0)([[1, 2], [3, 4]]); // => [1, 3] +}; () => { - R.prepend('fee', ['fi', 'fo', 'fum']); //=> ['fee', 'fi', 'fo', 'fum'] - R.prepend('fee')(['fi', 'fo', 'fum']); //=> ['fee', 'fi', 'fo', 'fum'] -} + R.prepend("fee", ["fi", "fo", "fum"]); // => ['fee', 'fi', 'fo', 'fum'] + R.prepend("fee")(["fi", "fo", "fum"]); // => ['fee', 'fi', 'fo', 'fum'] +}; () => { - R.range(1, 5); //=> [1, 2, 3, 4] - R.range(50)(53); //=> [50, 51, 52] -} + R.range(1, 5); // => [1, 2, 3, 4] + R.range(50)(53); // => [50, 51, 52] +}; () => { - var numbers = [1, 2, 3]; - var add = function(a: number, b: number) { + let numbers = [1, 2, 3]; + + function add(a: number, b: number) { return a + b; - }; - R.reduce(add, 10, numbers); //=> 16 - R.reduce(add)(10, numbers); //=> 16 - R.reduce(add, 10)(numbers); //=> 16 -} + } + + R.reduce(add, 10, numbers); // => 16 + R.reduce(add)(10, numbers); // => 16 + R.reduce(add, 10)(numbers); // => 16 +}; interface Student { name: string; score: number; } + () => { const reduceToNamesBy = R.reduceBy((acc: string[], student: Student) => acc.concat(student.name), []); - const namesByGrade = reduceToNamesBy(function(student) { - let score = student.score; - return score < 65 ? 'F' : - score < 70 ? 'D' : - score < 80 ? 'C' : - score < 90 ? 'B' : 'A'; + const namesByGrade = reduceToNamesBy((student) => { + let score = student.score; + return score < 65 ? "F" : + score < 70 ? "D" : + score < 80 ? "C" : + score < 90 ? "B" : "A"; }); - let students = [{name: 'Lucy', score: 92}, - {name: 'Drew', score: 85}, - {name: 'Bart', score: 62}]; - const names = namesByGrade(students); + let students = [{name: "Lucy", score: 92}, + {name: "Drew", score: 85}, + {name: "Bart", score: 62}]; + const names = namesByGrade(students); // { // 'A': ['Lucy'], // 'B': ['Drew'] // 'F': ['Bart'] // } -} +}; () => { - var reduceIndexed = R.addIndex(R.reduce); - var letters = ['a', 'b', 'c']; - var objectify = function(accObject: {[elem:string]: number}, elem: string, idx: number, list: string[]) { + let reduceIndexed = R.addIndex(R.reduce); + let letters = ["a", "b", "c"]; + + function objectify(accObject: { [elem: string]: number }, elem: string, idx: number, list: string[]) { accObject[elem] = idx; return accObject; - }; - reduceIndexed(objectify, {}, letters); //=> { 'a': 0, 'b': 1, 'c': 2 } - reduceIndexed(objectify)({}, letters); //=> { 'a': 0, 'b': 1, 'c': 2 } - reduceIndexed(objectify, {})(letters); //=> { 'a': 0, 'b': 1, 'c': 2 } -} + } + + reduceIndexed(objectify, {}, letters); // => { 'a': 0, 'b': 1, 'c': 2 } + reduceIndexed(objectify)({}, letters); // => { 'a': 0, 'b': 1, 'c': 2 } + reduceIndexed(objectify, {})(letters); // => { 'a': 0, 'b': 1, 'c': 2 } +}; + +interface KeyValuePair extends Array { + 0: K; + 1: V; +} +type Pair = KeyValuePair; -interface KeyValuePair extends Array { 0 : K; 1 : V; } -type Pair = KeyValuePair () => { - var pairs: Pair[] = [ ['a', 1], ['b', 2], ['c', 3] ]; - var flattenPairs = function(acc: Pair[], pair: Pair): Pair[] { + let pairs: Pair[] = [["a", 1], ["b", 2], ["c", 3]]; + + function flattenPairs(acc: Pair[], pair: Pair): Pair[] { return acc.concat(pair); - }; - R.reduceRight(flattenPairs, [], pairs); //=> [ 'c', 3, 'b', 2, 'a', 1 ] - R.reduceRight(flattenPairs, [])(pairs); //=> [ 'c', 3, 'b', 2, 'a', 1 ] - R.reduceRight(flattenPairs)([], pairs); //=> [ 'c', 3, 'b', 2, 'a', 1 ] -} + } + + R.reduceRight(flattenPairs, [], pairs); // => [ 'c', 3, 'b', 2, 'a', 1 ] + R.reduceRight(flattenPairs, [])(pairs); // => [ 'c', 3, 'b', 2, 'a', 1 ] + R.reduceRight(flattenPairs)([], pairs); // => [ 'c', 3, 'b', 2, 'a', 1 ] +}; () => { - var isOdd = function(n: number) { + function isOdd(n: number) { return n % 2 === 1; - }; - R.reject(isOdd, [1, 2, 3, 4]); //=> [2, 4] - R.reject(isOdd)([1, 2, 3, 4]); //=> [2, 4] -} + } + + R.reject(isOdd, [1, 2, 3, 4]); // => [2, 4] + R.reject(isOdd)([1, 2, 3, 4]); // => [2, 4] +}; () => { - const lastTwo = function(val: number, idx: number, list: number[]) { + function lastTwo(val: number, idx: number, list: number[]) { return list.length - idx <= 2; - }; + } + const rejectIndexed = R.addIndex(R.reject); - rejectIndexed(lastTwo, [8, 6, 7, 5, 3, 0, 9]); //=> [8, 6, 7, 5, 3] - rejectIndexed(lastTwo)([8, 6, 7, 5, 3, 0, 9]); //=> [8, 6, 7, 5, 3] -} + rejectIndexed(lastTwo, [8, 6, 7, 5, 3, 0, 9]); // => [8, 6, 7, 5, 3] + rejectIndexed(lastTwo)([8, 6, 7, 5, 3, 0, 9]); // => [8, 6, 7, 5, 3] +}; () => { - R.remove(2, 3, [1,2,3,4,5,6,7,8]); //=> [1,2,6,7,8] - R.remove(2, 3)([1,2,3,4,5,6,7,8]); //=> [1,2,6,7,8] - R.remove(2)(3, [1,2,3,4,5,6,7,8]); //=> [1,2,6,7,8] -} + R.remove(2, 3, [1, 2, 3, 4, 5, 6, 7, 8]); // => [1,2,6,7,8] + R.remove(2, 3)([1, 2, 3, 4, 5, 6, 7, 8]); // => [1,2,6,7,8] + R.remove(2)(3, [1, 2, 3, 4, 5, 6, 7, 8]); // => [1,2,6,7,8] +}; () => { - R.repeat('hi', 5); //=> ['hi', 'hi', 'hi', 'hi', 'hi'] - var obj = {}; - var repeatedObjs = R.repeat(obj, 5); //=> [{}, {}, {}, {}, {}] - repeatedObjs[0] === repeatedObjs[1]; //=> true -} + R.repeat("hi", 5); // => ['hi', 'hi', 'hi', 'hi', 'hi'] + let obj = {}; + let repeatedObjs = R.repeat(obj, 5); // => [{}, {}, {}, {}, {}] + repeatedObjs[0] === repeatedObjs[1]; // => true +}; () => { - R.reverse([1, 2, 3]); //=> [3, 2, 1] - R.reverse([1, 2]); //=> [2, 1] - R.reverse([1]); //=> [1] - R.reverse([]); //=> [] -} + R.reverse([1, 2, 3]); // => [3, 2, 1] + R.reverse([1, 2]); // => [2, 1] + R.reverse([1]); // => [1] + R.reverse([]); // => [] +}; () => { - var numbers = [1, 2, 3, 4]; - R.scan(R.multiply, 1, numbers); //=> [1, 1, 2, 6, 24] - R.scan(R.multiply, 1)(numbers); //=> [1, 1, 2, 6, 24] - R.scan(R.multiply)(1, numbers); //=> [1, 1, 2, 6, 24] -} + let numbers = [1, 2, 3, 4]; + R.scan(R.multiply, 1, numbers); // => [1, 1, 2, 6, 24] + R.scan(R.multiply, 1)(numbers); // => [1, 1, 2, 6, 24] + R.scan(R.multiply)(1, numbers); // => [1, 1, 2, 6, 24] +}; () => { - var xs = R.range(0, 10); - R.slice(2, 5, xs); //=> [2, 3, 4] - R.slice(2, 5)(xs); //=> [2, 3, 4] - R.slice(2)(5, xs); //=> [2, 3, 4] + let xs = R.range(0, 10); + R.slice(2, 5, xs); // => [2, 3, 4] + R.slice(2, 5)(xs); // => [2, 3, 4] + R.slice(2)(5, xs); // => [2, 3, 4] - var str = 'Hello World'; - R.slice(2, 5, str); //=> 'llo' - R.slice(2, 5)(str); //=> 'llo' - R.slice(2)(5, str); //=> 'llo' -} + let str = "Hello World"; + R.slice(2, 5, str); // => 'llo' + R.slice(2, 5)(str); // => 'llo' + R.slice(2)(5, str); // => 'llo' +}; () => { - var diff = function(a: number, b: number) { return a - b; }; - R.sort(diff, [4,2,7,5]); //=> [2, 4, 5, 7] - R.sort(diff)([4,2,7,5]); //=> [2, 4, 5, 7] -} + function diff(a: number, b: number) { + return a - b; + } + + R.sort(diff, [4, 2, 7, 5]); // => [2, 4, 5, 7] + R.sort(diff)([4, 2, 7, 5]); // => [2, 4, 5, 7] +}; () => { - const fn = R.cond([ - [R.equals(0), R.always('water freezes at 0°C')], - [R.equals(100), R.always('water boils at 100°C')], - [R.T, (temp: number) => 'nothing special happens at ' + temp + '°C'] + const fn = R.cond([ + [R.equals(0), R.always("water freezes at 0°C")], + [R.equals(100), R.always("water boils at 100°C")], + [R.T, (temp: number) => "nothing special happens at " + temp + "°C"] ]); - const a: string = fn(0); //=> 'water freezes at 0°C' - const b: string = fn(50); //=> 'nothing special happens at 50°C' - const c: string = fn(100); //=> 'water boils at 100°C' -} + const a: string = fn(0); // => 'water freezes at 0°C' + const b: string = fn(50); // => 'nothing special happens at 50°C' + const c: string = fn(100); // => 'water boils at 100°C' +}; () => { - R.tail(['fi', 'fo', 'fum']); //=> ['fo', 'fum'] - R.tail([1, 2, 3]); //=> [2, 3] - R.tail('abc'); //=> 'bc' - R.tail(''); //=> '' -} + R.tail(["fi", "fo", "fum"]); // => ['fo', 'fum'] + R.tail([1, 2, 3]); // => [2, 3] + R.tail("abc"); // => 'bc' + R.tail(""); // => '' +}; () => { - R.take(3,[1,2,3,4,5]); //=> [1,2,3] - - var members= [ "Paul Desmond","Bob Bates","Joe Dodge","Ron Crotty","Lloyd Davis","Joe Morello","Norman Bates", - "Eugene Wright","Gerry Mulligan","Jack Six","Alan Dawson","Darius Brubeck","Chris Brubeck", - "Dan Brubeck","Bobby Militello","Michael Moore","Randy Jones"]; - var takeFive = R.take(5); - takeFive(members); //=> ["Paul Desmond","Bob Bates","Joe Dodge","Ron Crotty","Lloyd Davis"] -} -() => { - R.take(3,"Example"); //=> "Exa" - - var takeThree = R.take(3); - takeThree("Example"); //=> "Exa" -} - + R.take(3, [1, 2, 3, 4, 5]); // => [1,2,3] + let members = ["Paul Desmond", "Bob Bates", "Joe Dodge", "Ron Crotty", "Lloyd Davis", "Joe Morello", "Norman Bates", + "Eugene Wright", "Gerry Mulligan", "Jack Six", "Alan Dawson", "Darius Brubeck", "Chris Brubeck", + "Dan Brubeck", "Bobby Militello", "Michael Moore", "Randy Jones"]; + let takeFive = R.take(5); + takeFive(members); // => ["Paul Desmond","Bob Bates","Joe Dodge","Ron Crotty","Lloyd Davis"] +}; () => { - const a: string[] = R.takeLast(1, ['foo', 'bar', 'baz']); //=> ['baz'] - const b: string[] = R.takeLast(2)(['foo', 'bar', 'baz']); //=> ['bar', 'baz'] - const c: string = R.takeLast(3, 'ramda'); //=> 'mda' - const d: string = R.takeLast(3)('ramda'); //=> 'mda' -} + R.take(3, "Example"); // => "Exa" + + let takeThree = R.take(3); + takeThree("Example"); // => "Exa" +}; () => { - const isNotOne = (x: number) => x !== 1; - const a: number[] = R.takeLastWhile(isNotOne, [1, 2, 3, 4]); //=> [2, 3, 4] - const b: number[] = R.takeLastWhile(isNotOne)([1, 2, 3, 4]); //=> [2, 3, 4] -} + const a: string[] = R.takeLast(1, ["foo", "bar", "baz"]); // => ['baz'] + const b: string[] = R.takeLast(2)(["foo", "bar", "baz"]); // => ['bar', 'baz'] + const c: string = R.takeLast(3, "ramda"); // => 'mda' + const d: string = R.takeLast(3)("ramda"); // => 'mda' +}; () => { - var isNotFour = function(x: number) { + const isNotOne = (x: number) => x !== 1; + const a: number[] = R.takeLastWhile(isNotOne, [1, 2, 3, 4]); // => [2, 3, 4] + const b: number[] = R.takeLastWhile(isNotOne)([1, 2, 3, 4]); // => [2, 3, 4] +}; + +() => { + function isNotFour(x: number) { return !(x === 4); - }; + } - R.takeWhile(isNotFour, [1, 2, 3, 4]); //=> [1, 2, 3] - R.takeWhile(isNotFour)([1, 2, 3, 4]); //=> [1, 2, 3] -} + R.takeWhile(isNotFour, [1, 2, 3, 4]); // => [1, 2, 3] + R.takeWhile(isNotFour)([1, 2, 3, 4]); // => [1, 2, 3] +}; () => { - const sayX = (x: number) => console.log('x is ' + x); - const a: number = R.tap(sayX, 100); //=> 100 -} + const sayX = (x: number) => console.log("x is " + x); + const a: number = R.tap(sayX, 100); // => 100 +}; () => { - const a: boolean = R.test(/^x/, 'xyz'); //=> true - const b: boolean = R.test(/^y/)('xyz'); //=> false -} + const a: boolean = R.test(/^x/, "xyz"); // => true + const b: boolean = R.test(/^y/)("xyz"); // => false +}; () => { - const a1 = R.times(R.identity, 5); //=> [0, 1, 2, 3, 4] - const a2 = R.times(R.identity)(5); //=> [0, 1, 2, 3, 4] -} + const a1 = R.times(R.identity, 5); // => [0, 1, 2, 3, 4] + const a2 = R.times(R.identity)(5); // => [0, 1, 2, 3, 4] +}; () => { - class Point { - constructor(public x: number, public y: number) { - this.x = x; - this.y = y; - } - toStringn() { - return 'new Point(' + this.x + ', ' + this.y + ')'; - } - }; - R.toString(new Point(1, 2)); //=> 'new Point(1, 2)' + class Point { + constructor(public x: number, public y: number) { + this.x = x; + this.y = y; + } - R.toString(42); //=> '42' - R.toString('abc'); //=> '"abc"' - R.toString([1, 2, 3]); //=> '[1, 2, 3]' - R.toString({foo: 1, bar: 2, baz: 3}); //=> '{"bar": 2, "baz": 3, "foo": 1}' - R.toString(new Date('2001-02-03T04:05:06Z')); //=> 'new Date("2001-02-03T04:05:06.000Z")' -} + toStringn() { + return "new Point(" + this.x + ", " + this.y + ")"; + } + } + R.toString(new Point(1, 2)); // => 'new Point(1, 2)' + + R.toString(42); // => '42' + R.toString("abc"); // => '"abc"' + R.toString([1, 2, 3]); // => '[1, 2, 3]' + R.toString({foo: 1, bar: 2, baz: 3}); // => '{"bar": 2, "baz": 3, "foo": 1}' + R.toString(new Date("2001-02-03T04:05:06Z")); // => 'new Date("2001-02-03T04:05:06.000Z")' +}; () => { - var numbers = [1, 2, 3, 4]; - var transducer = R.compose(R.map(R.add(1)), R.take(2)); - var fn = R.flip(R.append); - R.transduce(transducer, fn, [], numbers); //=> [2, 3] - R.transduce(transducer, fn, [])(numbers); //=> [2, 3] - R.transduce(transducer, fn)([], numbers); //=> [2, 3] - R.transduce(transducer)(fn, [], numbers); //=> [2, 3] -} + let numbers = [1, 2, 3, 4]; + let transducer = R.compose(R.map(R.add(1)), R.take(2)); + let fn = R.flip(R.append); + R.transduce(transducer, fn, [], numbers); // => [2, 3] + R.transduce(transducer, fn, [])(numbers); // => [2, 3] + R.transduce(transducer, fn)([], numbers); // => [2, 3] + R.transduce(transducer)(fn, [], numbers); // => [2, 3] +}; () => { - const a: (number | string)[][] = R.transpose([[1, 'a'], [2, 'b'], [3, 'c']]) //=> [[1, 2, 3], ['a', 'b', 'c']] - const b: (number | string)[][] = R.transpose([[1, 2, 3], ['a', 'b', 'c']]) //=> [[1, 'a'], [2, 'b'], [3, 'c']] - const c: number[][] = R.transpose([[10, 11], [20], [], [30, 31, 32]]) //=> [[10, 20, 30], [11, 31], [32]] -} + const a: Array> = R.transpose([[1, "a"], [2, "b"], [3, "c"]]); // => [[1, 2, 3], ['a', 'b', 'c']] + const b: Array> = R.transpose([[1, 2, 3], ["a", "b", "c"]]); // => [[1, 'a'], [2, 'b'], [3, 'c']] + const c: number[][] = R.transpose([[10, 11], [20], [], [30, 31, 32]]); // => [[10, 20, 30], [11, 31], [32]] +}; () => { - const x = R.prop('x'); - const a: boolean = R.tryCatch(R.prop('x'), R.F)({x: true}); //=> true - const b: boolean = R.tryCatch(R.prop('x'), R.F)(null); //=> false - const c: boolean = R.tryCatch(R.and, R.F)(true, true); //=> true -} + const x = R.prop("x"); + const a: boolean = R.tryCatch(R.prop("x"), R.F)({x: true}); // => true + const b: boolean = R.tryCatch(R.prop("x"), R.F)(null); // => false + const c: boolean = R.tryCatch(R.and, R.F)(true, true); // => true +}; () => { - R.uniq([1, 1, 2, 1]); //=> [1, 2] - R.uniq([{}, {}]); //=> [{}, {}] - R.uniq([1, '1']); //=> [1, '1'] -} + R.uniq([1, 1, 2, 1]); // => [1, 2] + R.uniq([{}, {}]); // => [{}, {}] + R.uniq([1, "1"]); // => [1, '1'] +}; () => { - var strEq = function(a: any, b: any) { return String(a) === String(b); }; - R.uniqWith(strEq, [1, '1', 2, 1]); //=> [1, 2] - R.uniqWith(strEq)([1, '1', 2, 1]); //=> [1, 2] - R.uniqWith(strEq)([{}, {}]); //=> [{}] - R.uniqWith(strEq)([1, '1', 1]); //=> [1] - R.uniqWith(strEq)(['1', 1, 1]); //=> ['1'] -} + function strEq(a: any, b: any) { + return String(a) === String(b); + } + + R.uniqWith(strEq, [1, "1", 2, 1]); // => [1, 2] + R.uniqWith(strEq)([1, "1", 2, 1]); // => [1, 2] + R.uniqWith(strEq)([{}, {}]); // => [{}] + R.uniqWith(strEq)([1, "1", 1]); // => [1] + R.uniqWith(strEq)(["1", 1, 1]); // => ['1'] +}; () => { - R.equals(R.unnest([1, [2], [[3]]]), [1,2,[3]]); //=> true - R.equals(R.unnest([[1, 2], [3, 4], [5, 6]]),[1,2,3,4,5,6]); //=> true -} + R.equals(R.unnest([1, [2], [[3]]]), [1, 2, [3]]); // => true + R.equals(R.unnest([[1, 2], [3, 4], [5, 6]]), [1, 2, 3, 4, 5, 6]); // => true +}; () => { - R.xprod([1, 2], ['a', 'b']); //=> [[1, 'a'], [1, 'b'], [2, 'a'], [2, 'b']] - R.xprod([1, 2])(['a', 'b']); //=> [[1, 'a'], [1, 'b'], [2, 'a'], [2, 'b']] -} + R.xprod([1, 2], ["a", "b"]); // => [[1, 'a'], [1, 'b'], [2, 'a'], [2, 'b']] + R.xprod([1, 2])(["a", "b"]); // => [[1, 'a'], [1, 'b'], [2, 'a'], [2, 'b']] +}; () => { - R.zip([1, 2, 3], ['a', 'b', 'c']); //=> [[1, 'a'], [2, 'b'], [3, 'c']] - R.zip([1, 2, 3])(['a', 'b', 'c']); //=> [[1, 'a'], [2, 'b'], [3, 'c']] -} + R.zip([1, 2, 3], ["a", "b", "c"]); // => [[1, 'a'], [2, 'b'], [3, 'c']] + R.zip([1, 2, 3])(["a", "b", "c"]); // => [[1, 'a'], [2, 'b'], [3, 'c']] +}; () => { - R.zipObj(['a', 'b', 'c'], [1, 2, 3]); //=> {a: 1, b: 2, c: 3} - R.zipObj(['a', 'b', 'c'])([1, 2, 3]); //=> {a: 1, b: 2, c: 3} -} + R.zipObj(["a", "b", "c"], [1, 2, 3]); // => {a: 1, b: 2, c: 3} + R.zipObj(["a", "b", "c"])([1, 2, 3]); // => {a: 1, b: 2, c: 3} +}; () => { - var f = function(x:number, y:string) { + function f(x: number, y: string) { // ... - }; - R.zipWith(f, [1, 2, 3], ['a', 'b', 'c']); //=> [f(1, 'a'), f(2, 'b'), f(3, 'c')] - R.zipWith(f)([1, 2, 3], ['a', 'b', 'c']); //=> [f(1, 'a'), f(2, 'b'), f(3, 'c')] - R.zipWith(f, [1, 2, 3])(['a', 'b', 'c']); //=> [f(1, 'a'), f(2, 'b'), f(3, 'c')] -} + } + + R.zipWith(f, [1, 2, 3], ["a", "b", "c"]); // => [f(1, 'a'), f(2, 'b'), f(3, 'c')] + R.zipWith(f)([1, 2, 3], ["a", "b", "c"]); // => [f(1, 'a'), f(2, 'b'), f(3, 'c')] + R.zipWith(f, [1, 2, 3])(["a", "b", "c"]); // => [f(1, 'a'), f(2, 'b'), f(3, 'c')] +}; /***************************************************************** * Object category */ () => { - type ABC = {a: number, b: number, c: number} - const a: ABC = R.assoc('c', 3, {a: 1, b: 2}); //=> {a: 1, b: 2, c: 3} - const b: ABC = R.assoc('c')(3, {a: 1, b: 2}); //=> {a: 1, b: 2, c: 3} - const c: ABC = R.assoc('c', 3)({a: 1, b: 2}); //=> {a: 1, b: 2, c: 3} -} + interface ABC { a: number; b: number; c: number; } + const a: ABC = R.assoc("c", 3, {a: 1, b: 2}); // => {a: 1, b: 2, c: 3} + const b: ABC = R.assoc("c")(3, {a: 1, b: 2}); // => {a: 1, b: 2, c: 3} + const c: ABC = R.assoc("c", 3)({a: 1, b: 2}); // => {a: 1, b: 2, c: 3} +}; () => { - const a1 = R.dissoc<{a:number, c:number}>('b', {a: 1, b: 2, c: 3}); //=> {a: 1, c: 3} - const a2 = R.dissoc('b', {a: 1, b: 2, c: 3}); //=> {a: 1, c: 3} - const a4 = R.dissoc('b')<{a:number, c:number}>({a: 1, b: 2, c: 3}); //=> {a: 1, c: 3} -} + const a1 = R.dissoc<{ a: number, c: number }>("b", {a: 1, b: 2, c: 3}); // => {a: 1, c: 3} + const a2 = R.dissoc("b", {a: 1, b: 2, c: 3}); // => {a: 1, c: 3} + const a4 = R.dissoc("b")<{ a: number, c: number }>({a: 1, b: 2, c: 3}); // => {a: 1, c: 3} +}; () => { - const testPath = ['x', 0, 'y']; - const testObj = {x: [{y: 2, z: 3}, {y: 4, z: 5}]}; + const testPath = ["x", 0, "y"]; + const testObj = {x: [{y: 2, z: 3}, {y: 4, z: 5}]}; - R.assocPath(testPath, 42, testObj); //=> {x: [{y: 42, z: 3}, {y: 4, z: 5}]} - R.assocPath(testPath, 42)(testObj); //=> {x: [{y: 42, z: 3}, {y: 4, z: 5}]} - R.assocPath(testPath)(42)(testObj); //=> {x: [{y: 42, z: 3}, {y: 4, z: 5}]} - R.assocPath(testPath)(42, testObj); //=> {x: [{y: 42, z: 3}, {y: 4, z: 5}]} -} + R.assocPath(testPath, 42, testObj); // => {x: [{y: 42, z: 3}, {y: 4, z: 5}]} + R.assocPath(testPath, 42)(testObj); // => {x: [{y: 42, z: 3}, {y: 4, z: 5}]} + R.assocPath(testPath)(42)(testObj); // => {x: [{y: 42, z: 3}, {y: 4, z: 5}]} + R.assocPath(testPath)(42, testObj); // => {x: [{y: 42, z: 3}, {y: 4, z: 5}]} +}; () => { - const a1 = R.dissocPath(['a', 'b', 'c'], {a: {b: {c: 42}}}); //=> {a: {b: {}}} + const a1 = R.dissocPath(["a", "b", "c"], {a: {b: {c: 42}}}); // => {a: {b: {}}} // optionally specify return type - const a2 = R.dissocPath<{a :{ b: number}}>(['a', 'b', 'c'], {a: {b: {c: 42}}}); //=> {a: {b: {}}} - const a3 = R.dissocPath(['a', 'b', 'c'])({a: {b: {c: 42}}}); //=> {a: {b: {}}} + const a2 = R.dissocPath<{ a: { b: number } }>(["a", "b", "c"], {a: {b: {c: 42}}}); // => {a: {b: {}}} + const a3 = R.dissocPath(["a", "b", "c"])({a: {b: {c: 42}}}); // => {a: {b: {}}} - const testPath = ['x', 0, 'y']; - const testObj = {x: [{y: 2, z: 3}, {y: 4, z: 5}]}; + const testPath = ["x", 0, "y"]; + const testObj = {x: [{y: 2, z: 3}, {y: 4, z: 5}]}; - R.dissocPath(testPath, testObj); //=> {x: [{z: 3}, {y: 4, z: 5}]} - R.dissocPath(testPath)(testObj); //=> {x: [{z: 3}, {y: 4, z: 5}]} -} + R.dissocPath(testPath, testObj); // => {x: [{z: 3}, {y: 4, z: 5}]} + R.dissocPath(testPath)(testObj); // => {x: [{z: 3}, {y: 4, z: 5}]} +}; () => { - var obj1 = [{}, {}, {}]; - var obj2 = [{a:1}, {a:2}, {a:3}]; - const a1: any[] = R.clone(obj1); - const a2: {a: number}[] = R.clone(obj2); - const a3: any = R.clone({}); - const a4: number = R.clone(10); - const a5: string = R.clone('foo'); - const a6: number = R.clone(Date.now()); -} + let obj1 = [{}, {}, {}]; + let obj2 = [{a: 1}, {a: 2}, {a: 3}]; + const a1: any[] = R.clone(obj1); + const a2: Array<{ a: number }> = R.clone(obj2); + const a3: any = R.clone({}); + const a4: number = R.clone(10); + const a5: string = R.clone("foo"); + const a6: number = R.clone(Date.now()); +}; () => { - var o1 = { a: 1, b: 2, c: 3, d: 4 }; - var o2 = { a: 10, b: 20, c: 3, d: 40 }; - const a1 = R.eqProps('a', o1, o2); //=> false - const a2 = R.eqProps('c', o1, o2); //=> true - const a3: {(obj1: T, obj2: U): boolean} = R.eqProps('c'); - const a4: {(obj2: U): boolean} = R.eqProps('c', o1); -} + let o1 = {a: 1, b: 2, c: 3, d: 4}; + let o2 = {a: 10, b: 20, c: 3, d: 40}; + const a1 = R.eqProps("a", o1, o2); // => false + const a2 = R.eqProps("c", o1, o2); // => true + const a3: (obj1: T, obj2: U) => boolean = R.eqProps("c"); + const a4: (obj2: U) => boolean = R.eqProps("c", o1); +}; () => { - const a1 = R.evolve({ elapsed: R.add(1), remaining: R.add(-1) }, { name: 'Tomato', elapsed: 100, remaining: 1400 }); - const a2 = R.evolve({ elapsed: R.add(1), remaining: R.add(-1) })({ name: 'Tomato', elapsed: 100, remaining: 1400 }); -} + const a1 = R.evolve({elapsed: R.add(1), remaining: R.add(-1)}, {name: "Tomato", elapsed: 100, remaining: 1400}); + const a2 = R.evolve({elapsed: R.add(1), remaining: R.add(-1)})({name: "Tomato", elapsed: 100, remaining: 1400}); +}; () => { - // var tomato = {firstName: 'Tomato ', data: {elapsed: 100, remaining: 1400}, id:123}; - // var transformations = { + // let tomato = {firstName: 'Tomato ', data: {elapsed: 100, remaining: 1400}, id:123}; + // let transformations = { // firstName: R.trim, // lastName: R.trim, // Will not get invoked. // data: {elapsed: R.add(1), remaining: R.add(-1)} // }; - // const a = R.evolve(transformations, tomato); //=> {firstName: 'Tomato', data: {elapsed: 101, remaining: 1399}, id:123} - // const b = R.evolve(transformations)(tomato); //=> {firstName: 'Tomato', data: {elapsed: 101, remaining: 1399}, id:123} -} + // const a = R.evolve(transformations, tomato); // => {firstName: 'Tomato', data: {elapsed: 101, remaining: 1399}, id:123} + // const b = R.evolve(transformations)(tomato); // => {firstName: 'Tomato', data: {elapsed: 101, remaining: 1399}, id:123} +}; () => { - const hasName = R.has('name'); - const a1: boolean = hasName({name: 'alice'}); //=> true - const a2: boolean = hasName({name: 'bob'}); //=> true - const a3: boolean = hasName({}); //=> false + const hasName = R.has("name"); + const a1: boolean = hasName({name: "alice"}); // => true + const a2: boolean = hasName({name: "bob"}); // => true + const a3: boolean = hasName({}); // => false - const point = {x: 0, y: 0}; - const pointHas = R.flip(R.has)(point); - const b1: boolean = pointHas('x'); //=> true - const b2: boolean = pointHas('y'); //=> true - const b3: boolean = pointHas('z'); //=> false -} + const point = {x: 0, y: 0}; + const pointHas = R.flip(R.has)(point); + const b1: boolean = pointHas("x"); // => true + const b2: boolean = pointHas("y"); // => true + const b3: boolean = pointHas("z"); // => false +}; class Rectangle { constructor(public width: number, public height: number) { - this.width = width; + this.width = width; this.height = height; } - area():number { + + area(): number { return this.width * this.height; } -}; -() => { - - var square = new Rectangle(2, 2); - R.hasIn('width', square); //=> true - R.hasIn('area', square); //=> true - R.flip(R.hasIn)(square)('area'); //=> true } () => { - var raceResultsByFirstName = { - first: 'alice', - second: 'jake', - third: 'alice', + let square = new Rectangle(2, 2); + R.hasIn("width", square); // => true + R.hasIn("area", square); // => true + R.flip(R.hasIn)(square)("area"); // => true +}; + +() => { + let raceResultsByFirstName = { + first : "alice", + second: "jake", + third : "alice", }; R.invert(raceResultsByFirstName); - //=> { 'alice': ['first', 'third'], 'jake':['second'] } -} + // => { 'alice': ['first', 'third'], 'jake':['second'] } +}; () => { let raceResults0 = { - first: 'alice', - second: 'jake' + first : "alice", + second: "jake" }; R.invertObj(raceResults0); - //=> { 'alice': 'first', 'jake':'second' } + // => { 'alice': 'first', 'jake':'second' } // Alternatively: - let raceResults1 = ['alice', 'jake']; + let raceResults1 = ["alice", "jake"]; R.invertObj(raceResults1); - //=> { 'alice': '0', 'jake':'1' } -} + // => { 'alice': '0', 'jake':'1' } +}; () => { - R.keys({a: 1, b: 2, c: 3}); //=> ['a', 'b', 'c'] -} + R.keys({a: 1, b: 2, c: 3}); // => ['a', 'b', 'c'] +}; () => { - var f = new F(); - R.keysIn(f); //=> ['x', 'y'] -} + let f = new F(); + R.keysIn(f); // => ['x', 'y'] +}; () => { - var xLens = R.lens(R.prop('x'), R.assoc('x')); - R.view(xLens, {x: 1, y: 2}); //=> 1 - R.view(xLens)({x: 1, y: 2}); //=> 1 - R.set(xLens, 4, {x: 1, y: 2}); //=> {x: 4, y: 2} - R.set(xLens)(4, {x: 1, y: 2}); //=> {x: 4, y: 2} - R.set(xLens, 4)({x: 1, y: 2}); //=> {x: 4, y: 2} - R.over(xLens, R.negate, {x: 1, y: 2}); //=> {x: -1, y: 2} - R.over(xLens, R.negate)({x: 1, y: 2}); //=> {x: -1, y: 2} - R.over(xLens)(R.negate, {x: 1, y: 2}); //=> {x: -1, y: 2} -} -() => { - var headLens = R.lensIndex(0); - R.view(headLens, ['a', 'b', 'c']); //=> 'a' - R.set(headLens, 'x', ['a', 'b', 'c']); //=> ['x', 'b', 'c'] - R.over(headLens, R.toUpper, ['a', 'b', 'c']); //=> ['A', 'b', 'c'] -} -() => { - var xLens = R.lensProp('x'); - R.view(xLens, {x: 1, y: 2}); //=> 1 - R.set(xLens, 4, {x: 1, y: 2}); //=> {x: 4, y: 2} - R.over(xLens, R.negate, {x: 1, y: 2}); //=> {x: -1, y: 2} -} + let xLens = R.lens(R.prop("x"), R.assoc("x")); + R.view(xLens, {x: 1, y: 2}); // => 1 + R.view(xLens)({x: 1, y: 2}); // => 1 + R.set(xLens, 4, {x: 1, y: 2}); // => {x: 4, y: 2} + R.set(xLens)(4, {x: 1, y: 2}); // => {x: 4, y: 2} + R.set(xLens, 4)({x: 1, y: 2}); // => {x: 4, y: 2} + R.over(xLens, R.negate, {x: 1, y: 2}); // => {x: -1, y: 2} + R.over(xLens, R.negate)({x: 1, y: 2}); // => {x: -1, y: 2} + R.over(xLens)(R.negate, {x: 1, y: 2}); // => {x: -1, y: 2} +}; () => { - const xyLens = R.lensPath(['x', 0, 'y']); - const testObj = {x: [{y: 2, z: 3}, {y: 4, z: 5}]}; - - R.view(xyLens, testObj); //=> 2 - R.set(xyLens, 4, testObj); //=> {x: [{y: 4, z: 3}, {y: 4, z: 5}]} - R.over(xyLens, R.negate, testObj); //=> {x: [{y: -2, z: 3}, {y: 4, z: 5}]} -} + let headLens = R.lensIndex(0); + R.view(headLens, ["a", "b", "c"]); // => 'a' + R.set(headLens, "x", ["a", "b", "c"]); // => ['x', 'b', 'c'] + R.over(headLens, R.toUpper, ["a", "b", "c"]); // => ['A', 'b', 'c'] +}; () => { - R.keys({a: 1, b: 2, c: 3}); //=> ['a', 'b', 'c'] -} + let xLens = R.lensProp("x"); + R.view(xLens, {x: 1, y: 2}); // => 1 + R.set(xLens, 4, {x: 1, y: 2}); // => {x: 4, y: 2} + R.over(xLens, R.negate, {x: 1, y: 2}); // => {x: -1, y: 2} +}; () => { - var f = new F(); - R.keysIn(f); //=> ['x', 'y'] -} + const xyLens = R.lensPath(["x", 0, "y"]); + const testObj = {x: [{y: 2, z: 3}, {y: 4, z: 5}]}; + + R.view(xyLens, testObj); // => 2 + R.set(xyLens, 4, testObj); // => {x: [{y: 4, z: 3}, {y: 4, z: 5}]} + R.over(xyLens, R.negate, testObj); // => {x: [{y: -2, z: 3}, {y: 4, z: 5}]} +}; () => { - var headLens = R.lens( - function get(arr: number[]) { return arr[0]; }, - function set(val: number, arr: number[]) { return [val].concat(arr.slice(1)); } + R.keys({a: 1, b: 2, c: 3}); // => ['a', 'b', 'c'] +}; + +() => { + let f = new F(); + R.keysIn(f); // => ['x', 'y'] +}; + +() => { + let headLens = R.lens( + function get(arr: number[]) { + return arr[0]; + }, + function set(val: number, arr: number[]) { + return [val].concat(arr.slice(1)); + } ); - headLens([10, 20, 30, 40]); //=> 10 - headLens.set('mu', [10, 20, 30, 40]); //=> ['mu', 20, 30, 40] + headLens([10, 20, 30, 40]); // => 10 + headLens.set("mu", [10, 20, 30, 40]); // => ['mu', 20, 30, 40] - var phraseLens = R.lens( - function get(obj: any) { return obj.phrase; }, - function set(val: string, obj: any) { - var out = R.clone(obj); - out.phrase = val; - return out; - } + let phraseLens = R.lens( + function get(obj: any) { + return obj.phrase; + }, + function set(val: string, obj: any) { + let out = R.clone(obj); + out.phrase = val; + return out; + } ); - var obj1 = { phrase: 'Absolute filth . . . and I LOVED it!'}; - var obj2 = { phrase: "What's all this, then?"}; + let obj1 = {phrase: "Absolute filth . . . and I LOVED it!"}; + let obj2 = {phrase: "What's all this, then?"}; phraseLens(obj1); // => 'Absolute filth . . . and I LOVED it!' phraseLens(obj2); // => "What's all this, then?" - phraseLens.set('Ooh Betty', obj1); //=> { phrase: 'Ooh Betty'} -} - + phraseLens.set("Ooh Betty", obj1); // => { phrase: 'Ooh Betty'} +}; () => { - var phraseLens = R.lensProp('phrase'); - var obj1 = { phrase: 'Absolute filth . . . and I LOVED it!'}; - var obj2 = { phrase: "What's all this, then?"}; + let phraseLens = R.lensProp("phrase"); + let obj1 = {phrase: "Absolute filth . . . and I LOVED it!"}; + let obj2 = {phrase: "What's all this, then?"}; phraseLens(obj1); // => 'Absolute filth . . . and I LOVED it!' phraseLens(obj2); // => "What's all this, then?" - phraseLens.set('Ooh Betty', obj1); //=> { phrase: 'Ooh Betty'} -} + phraseLens.set("Ooh Betty", obj1); // => { phrase: 'Ooh Betty'} +}; () => { - R.merge({ 'name': 'fred', 'age': 10 }, { 'age': 40 }); - //=> { 'name': 'fred', 'age': 40 } + R.merge({name: "fred", age: 10}, {age: 40}); + // => { 'name': 'fred', 'age': 40 } - var resetToDefault = R.flip(R.merge)({x: 0}); - resetToDefault({x: 5, y: 2}); //=> {x: 0, y: 2} -} + let resetToDefault = R.flip(R.merge)({x: 0}); + resetToDefault({x: 5, y: 2}); // => {x: 0, y: 2} +}; () => { - const a = R.mergeAll([{foo:1},{bar:2},{baz:3}]); //=> {foo:1,bar:2,baz:3} - const b = R.mergeAll([{foo:1},{foo:2},{bar:2}]); //=> {foo:2,bar:2} -} + const a = R.mergeAll([{foo: 1}, {bar: 2}, {baz: 3}]); // => {foo:1,bar:2,baz:3} + const b = R.mergeAll([{foo: 1}, {foo: 2}, {bar: 2}]); // => {foo:2,bar:2} +}; () => { const a = R.mergeWith(R.concat, - { a: true, values: [10, 20] }, - { b: true, values: [15, 35] }); - //=> { a: true, b: true, values: [10, 20, 15, 35] } -} + {a: true, values: [10, 20]}, + {b: true, values: [15, 35]}); + // => { a: true, b: true, values: [10, 20, 15, 35] } +}; () => { - let concatValues = (k:string, l: string, r: string) => k == 'values' ? R.concat(l, r) : r; + let concatValues = (k: string, l: string, r: string) => k === "values" ? R.concat(l, r) : r; R.mergeWithKey(concatValues, - { a: true, thing: 'foo', values: [10, 20] }, - { b: true, thing: 'bar', values: [15, 35] }); + {a: true, thing: "foo", values: [10, 20]}, + {b: true, thing: "bar", values: [15, 35]}); const merge = R.mergeWithKey(concatValues); - merge({ a: true, thing: 'foo', values: [10, 20] }, { b: true, thing: 'bar', values: [15, 35] }); -} + merge({a: true, thing: "foo", values: [10, 20]}, {b: true, thing: "bar", values: [15, 35]}); +}; () => { - const orValue = 'N/A'; - const testPath = ['x', 0, 'y']; - const testObj = {x: [{y: 2, z: 3}, {y: 4, z: 5}]}; + const orValue = "N/A"; + const testPath = ["x", 0, "y"]; + const testObj = {x: [{y: 2, z: 3}, {y: 4, z: 5}]}; - R.pathOr(orValue, testPath, testObj); //=> 2 - R.pathOr(orValue, testPath)(testObj); //=> 2 - R.pathOr(orValue)(testPath)(testObj); //=> 2 - R.pathOr(orValue)(testPath, testObj); //=> 2 - R.pathOr(orValue, testPath, {c: {b: 2}}); //=> "N/A" -} + R.pathOr(orValue, testPath, testObj); // => 2 + R.pathOr(orValue, testPath)(testObj); // => 2 + R.pathOr(orValue)(testPath)(testObj); // => 2 + R.pathOr(orValue)(testPath, testObj); // => 2 + R.pathOr(orValue, testPath, {c: {b: 2}}); // => "N/A" +}; () => { - const a: boolean = R.pathSatisfies(x => x > 0, ['x'], {x: 1, y: 2}); //=> true - const b: boolean = R.pathSatisfies(x => x > 0, ['x'])({x: 1, y: 2}); //=> true - const c: boolean = R.pathSatisfies(x => x > 0)(['x'])({x: 1, y: 2}); //=> true -} + const a: boolean = R.pathSatisfies(x => x > 0, ["x"], {x: 1, y: 2}); // => true + const b: boolean = R.pathSatisfies(x => x > 0, ["x"])({x: 1, y: 2}); // => true + const c: boolean = R.pathSatisfies(x => x > 0)(["x"])({x: 1, y: 2}); // => true +}; () => { - var isPositive = function(n: number) { + function isPositive(n: number) { return n > 0; - }; - const a1 = R.pickBy(isPositive, {a: 1, b: 2, c: -1, d: 0, e: 5}); //=> {a: 1, b: 2, e: 5} - var containsBackground = function(val: any) { + } + + const a1 = R.pickBy(isPositive, {a: 1, b: 2, c: -1, d: 0, e: 5}); // => {a: 1, b: 2, e: 5} + function containsBackground(val: any) { return val.bgcolor; - }; - var colors = {1: {color: 'read'}, 2: {color: 'black', bgcolor: 'yellow'}}; - R.pickBy(containsBackground, colors); //=> {2: {color: 'black', bgcolor: 'yellow'}} + } - var isUpperCase = function(val: number, key: string) { return key.toUpperCase() === key; } - R.pickBy(isUpperCase, {a: 1, b: 2, A: 3, B: 4}); //=> {A: 3, B: 4} -} + let colors = {1: {color: "read"}, 2: {color: "black", bgcolor: "yellow"}}; + R.pickBy(containsBackground, colors); // => {2: {color: 'black', bgcolor: 'yellow'}} + function isUpperCase(val: number, key: string) { + return key.toUpperCase() === key; + } + + R.pickBy(isUpperCase, {a: 1, b: 2, A: 3, B: 4}); // => {A: 3, B: 4} +}; () => { - const a1 = R.pick(['a', 'd'], {a: 1, b: 2, c: 3, d: 4}); //=> {a: 1, d: 4} - const a2 = R.pick(['a', 'e', 'f'], {a: 1, b: 2, c: 3, d: 4}); //=> {a: 1} - const a3 = R.pick(['a', 'e', 'f'])({a: 1, b: 2, c: 3, d: 4}); //=> {a: 1} - const a4 = R.pick(['a', 'e', 'f'], [1, 2, 3, 4]); //=> {a: 1} -} + const a1 = R.pick(["a", "d"], {a: 1, b: 2, c: 3, d: 4}); // => {a: 1, d: 4} + const a2 = R.pick(["a", "e", "f"], {a: 1, b: 2, c: 3, d: 4}); // => {a: 1} + const a3 = R.pick(["a", "e", "f"])({a: 1, b: 2, c: 3, d: 4}); // => {a: 1} + const a4 = R.pick(["a", "e", "f"], [1, 2, 3, 4]); // => {a: 1} +}; () => { - const matchPhrases = (xs: string[]) => R.objOf('must', + const matchPhrases = (xs: string[]) => R.objOf("must", R.map( - (x: string) => R.objOf('match_phrase', x), + (x: string) => R.objOf("match_phrase", x), xs ) - ) - - const out: {must: Array<{match_phrase: string}>} = - matchPhrases(['foo', 'bar', 'baz']); -} -() => { - R.omit(['a', 'd'], {a: 1, b: 2, c: 3, d: 4}); //=> {b: 2, c: 3} - R.omit(['a', 'd'])({a: 1, b: 2, c: 3, d: 4}); //=> {b: 2, c: 3} -} + ); + const out: { must: Array<{ match_phrase: string }> } = + matchPhrases(["foo", "bar", "baz"]); +}; () => { - R.fromPairs([['a', 1], ['b', 2], ['c', 3]]); //=> {a: 1, b: 2, c: 3} -} + R.omit(["a", "d"], {a: 1, b: 2, c: 3, d: 4}); // => {b: 2, c: 3} + R.omit(["a", "d"])({a: 1, b: 2, c: 3, d: 4}); // => {b: 2, c: 3} +}; () => { - R.pair('foo', 'bar'); //=> ['foo', 'bar'] - let p = R.pair('foo', 1); //=> ['foo', 'bar'] + R.fromPairs([["a", 1], ["b", 2], ["c", 3]]); // => {a: 1, b: 2, c: 3} +}; + +() => { + R.pair("foo", "bar"); // => ['foo', 'bar'] + let p = R.pair("foo", 1); // => ['foo', 'bar'] let x: string = p[0]; let y: number = p[1]; -} +}; () => { - var headLens = R.lensIndex(0); - R.over(headLens, R.toUpper, ['foo', 'bar', 'baz']); //=> ['FOO', 'bar', 'baz'] -} + let headLens = R.lensIndex(0); + R.over(headLens, R.toUpper, ["foo", "bar", "baz"]); // => ['FOO', 'bar', 'baz'] +}; () => { - R.pickAll(['a', 'd'], {a: 1, b: 2, c: 3, d: 4}); //=> {a: 1, d: 4} - R.pickAll(['a', 'd'])({a: 1, b: 2, c: 3, d: 4}); //=> {a: 1, d: 4} - R.pickAll(['a', 'e', 'f'], {a: 1, b: 2, c: 3, d: 4}); //=> {a: 1, e: undefined, f: undefined} - R.pickAll(['a', 'e', 'f'])({a: 1, b: 2, c: 3, d: 4}); //=> {a: 1, e: undefined, f: undefined} -} + R.pickAll(["a", "d"], {a: 1, b: 2, c: 3, d: 4}); // => {a: 1, d: 4} + R.pickAll(["a", "d"])({a: 1, b: 2, c: 3, d: 4}); // => {a: 1, d: 4} + R.pickAll(["a", "e", "f"], {a: 1, b: 2, c: 3, d: 4}); // => {a: 1, e: undefined, f: undefined} + R.pickAll(["a", "e", "f"])({a: 1, b: 2, c: 3, d: 4}); // => {a: 1, e: undefined, f: undefined} +}; () => { - var isUpperCase = function(val: number, key: string) { return key.toUpperCase() === key; } - R.pickBy(isUpperCase, {a: 1, b: 2, A: 3, B: 4}); //=> {A: 3, B: 4} -} + function isUpperCase(val: number, key: string) { + return key.toUpperCase() === key; + } + + R.pickBy(isUpperCase, {a: 1, b: 2, A: 3, B: 4}); // => {A: 3, B: 4} +}; () => { - var abby = {name: 'Abby', age: 7, hair: 'blond', grade: 2}; - var fred = {name: 'Fred', age: 12, hair: 'brown', grade: 7}; - var kids = [abby, fred]; - R.project(['name', 'grade'], kids); //=> [{name: 'Abby', grade: 2}, {name: 'Fred', grade: 7}] -} + let abby = {name: "Abby", age: 7, hair: "blond", grade: 2}; + let fred = {name: "Fred", age: 12, hair: "brown", grade: 7}; + let kids = [abby, fred]; + R.project(["name", "grade"], kids); // => [{name: 'Abby', grade: 2}, {name: 'Fred', grade: 7}] +}; () => { - var x: number = R.prop('x', {x: 100}); //=> 100 - const a = R.prop('x', {}); //=> undefined -} + let x: number = R.prop("x", {x: 100}); // => 100 + const a = R.prop("x", {}); // => undefined +}; () => { - var alice = { - name: 'ALICE', - age: 101 + let alice = { + name: "ALICE", + age : 101 }; - var favorite = R.prop('favoriteLibrary'); - var favoriteWithDefault = R.propOr('Ramda', 'favoriteLibrary'); + let favorite = R.prop("favoriteLibrary"); + let favoriteWithDefault = R.propOr("Ramda", "favoriteLibrary"); - const s1 = favorite(alice); //=> undefined - const s2 = favoriteWithDefault(alice); //=> 'Ramda' -} + const s1 = favorite(alice); // => undefined + const s2 = favoriteWithDefault(alice); // => 'Ramda' +}; () => { - const a: boolean = R.propSatisfies(x => x > 0, 'x', {x: 1, y: 2}); //=> true - const b: boolean = R.propSatisfies(x => x > 0, 'x')({x: 1, y: 2}); //=> true - const c: boolean = R.propSatisfies(x => x > 0)('x')({x: 1, y: 2}); //=> true -} + const a: boolean = R.propSatisfies(x => x > 0, "x", {x: 1, y: 2}); // => true + const b: boolean = R.propSatisfies(x => x > 0, "x")({x: 1, y: 2}); // => true + const c: boolean = R.propSatisfies(x => x > 0)("x")({x: 1, y: 2}); // => true +}; () => { - R.props(['x', 'y'], {x: 1, y: 2}); //=> [1, 2] - R.props(['c', 'a', 'b'], {b: 2, a: 1}); //=> [undefined, 1, 2] + R.props(["x", "y"], {x: 1, y: 2}); // => [1, 2] + R.props(["c", "a", "b"], {b: 2, a: 1}); // => [undefined, 1, 2] - var fullName = R.compose(R.join(' '), R.props(['first', 'last'])); - fullName({last: 'Bullet-Tooth', age: 33, first: 'Tony'}); //=> 'Tony Bullet-Tooth' -} + let fullName = R.compose(R.join(" "), R.props(["first", "last"])); + fullName({last: "Bullet-Tooth", age: 33, first: "Tony"}); // => 'Tony Bullet-Tooth' +}; () => { - const a = R.toPairs({a: 1, b: 2, c: 3}); //=> [['a', 1], ['b', 2], ['c', 3]] -} + const a = R.toPairs({a: 1, b: 2, c: 3}); // => [['a', 1], ['b', 2], ['c', 3]] +}; () => { - var f = new F(); - const a1 = R.toPairsIn(f); //=> [['x','X'], ['y','Y']] - const a2 = R.toPairsIn(f); //=> [['x','X'], ['y','Y']] -} + let f = new F(); + const a1 = R.toPairsIn(f); // => [['x','X'], ['y','Y']] + const a2 = R.toPairsIn(f); // => [['x','X'], ['y','Y']] +}; () => { - const a = R.values({a: 1, b: 2, c: 3}); //=> [1, 2, 3] -} -() => { - var f = new F(); - const a = R.valuesIn(f); //=> ['X', 'Y'] -} + const a = R.values({a: 1, b: 2, c: 3}); // => [1, 2, 3] +}; () => { - var spec = {x: 2}; - var x1: boolean = R.where(spec, {w: 10, x: 2, y: 300}); //=> true - var x2: boolean = R.where(spec, {x: 1, y: 'moo', z: true}); //=> false - var x3: boolean = R.where(spec)({w: 10, x: 2, y: 300}); //=> true - var x4: boolean = R.where(spec)({x: 1, y: 'moo', z: true}); //=> false + let f = new F(); + const a = R.valuesIn(f); // => ['X', 'Y'] +}; + +() => { + let spec = {x: 2}; + let x1: boolean = R.where(spec, {w: 10, x: 2, y: 300}); // => true + let x2: boolean = R.where(spec, {x: 1, y: "moo", z: true}); // => false + let x3: boolean = R.where(spec)({w: 10, x: 2, y: 300}); // => true + let x4: boolean = R.where(spec)({x: 1, y: "moo", z: true}); // => false // There's no way to represent the below functionality in typescript // per http://stackoverflow.com/a/29803848/632495 // will need a work around. - var spec2 = {x: function(val: number, obj: any) { return val + obj.y > 10; }}; - R.where(spec2, {x: 2, y: 7}); //=> false - R.where(spec2, {x: 3, y: 8}); //=> true + let spec2 = { + x: (val: number, obj: any) => val + obj.y > 10 + }; + R.where(spec2, {x: 2, y: 7}); // => false + R.where(spec2, {x: 3, y: 8}); // => true - var xs = [{x: 2, y: 1}, {x: 10, y: 2}, {x: 8, y: 3}, {x: 10, y: 4}]; + let xs = [{x: 2, y: 1}, {x: 10, y: 2}, {x: 8, y: 3}, {x: 10, y: 4}]; R.filter(R.where({x: 10}), xs); // ==> [{x: 10, y: 2}, {x: 10, y: 4}] R.filter(R.where({x: 10}))(xs); // ==> [{x: 10, y: 2}, {x: 10, y: 4}] -} +}; () => { // pred :: Object -> Boolean - var pred = R.whereEq({a: 1, b: 2}); - pred({a: 1}); //=> false - pred({a: 1, b: 2}); //=> true - pred({a: 1, b: 2, c: 3}); //=> true - pred({a: 1, b: 1}); //=> false - R.whereEq({a: 'one'}, {a: 'one'}); // => true -} + let pred = R.whereEq({a: 1, b: 2}); + pred({a: 1}); // => false + pred({a: 1, b: 2}); // => true + pred({a: 1, b: 2, c: 3}); // => true + pred({a: 1, b: 1}); // => false + R.whereEq({a: "one"}, {a: "one"}); // => true +}; () => { - const a: number[] = R.without([1, 2], [1, 2, 1, 3, 4]); //=> [3, 4] -} + const a: number[] = R.without([1, 2], [1, 2, 1, 3, 4]); // => [3, 4] +}; () => { - var mapIndexed = R.addIndex(R.map); - mapIndexed(function(val: string, idx: number) {return idx + '-' + val;})(['f', 'o', 'o', 'b', 'a', 'r']); - //=> ['0-f', '1-o', '2-o', '3-b', '4-a', '5-r'] - mapIndexed((rectangle: Rectangle, idx: number):number => rectangle.area()*idx, [new Rectangle(1,2), new Rectangle(4,7)]); - //=> [2, 56] -} + let mapIndexed = R.addIndex(R.map); + mapIndexed((val: string, idx: number) => idx + "-" + val)(["f", "o", "o", "b", "a", "r"]); + // => ['0-f', '1-o', '2-o', '3-b', '4-a', '5-r'] + mapIndexed((rectangle: Rectangle, idx: number): number => rectangle.area() * idx, [new Rectangle(1, 2), new Rectangle(4, 7)]); + // => [2, 56] +}; () => { - var reduceIndexed = R.addIndex(R.reduce); - reduceIndexed(function(acc: string, val: string, idx: number) { - return acc + ',' + idx + '-' + val; - } - ,'' - ,['f', 'o', 'o', 'b', 'a', 'r']); - //=> ['0-f,1-o,2-o,3-b,4-a,5-r'] -} - - + let reduceIndexed = R.addIndex(R.reduce); + reduceIndexed((acc: string, val: string, idx: number) => acc + "," + idx + "-" + val, "", ["f", "o", "o", "b", "a", "r"]); + // => ['0-f,1-o,2-o,3-b,4-a,5-r'] +}; () => { - var t = R.always('Tee'); - const x: string = t(); //=> 'Tee' -} + let t = R.always("Tee"); + const x: string = t(); // => 'Tee' +}; () => { - const x: number[] = R.ap([R.multiply(2), R.add(3)], [1,2,3]); //=> [2, 4, 6, 4, 5, 6] - const y: number[] = R.ap([R.multiply(2), R.add(3)])([1,2,3]); //=> [2, 4, 6, 4, 5, 6] -} + const x: number[] = R.ap([R.multiply(2), R.add(3)], [1, 2, 3]); // => [2, 4, 6, 4, 5, 6] + const y: number[] = R.ap([R.multiply(2), R.add(3)])([1, 2, 3]); // => [2, 4, 6, 4, 5, 6] +}; () => { - var nums = [1, 2, 3, -99, 42, 6, 7]; - R.apply(Math.max, nums); //=> 42 - R.apply(Math.max)(nums); //=> 42 -} + let nums = [1, 2, 3, -99, 42, 6, 7]; + R.apply(Math.max, nums); // => 42 + R.apply(Math.max)(nums); // => 42 +}; () => { - type T = {sum: number, nested: {mul: number}}; + interface T { sum: number; nested: { mul: number; }; } const getMetrics = R.applySpec({ - sum: R.add, nested: { mul: R.multiply } + sum: R.add, nested: {mul: R.multiply} }); - const result = getMetrics(2, 4); // => { sum: 6, nested: { mul: 8 } } -} + const result = getMetrics(2, 4); // => { sum: 6, nested: { mul: 8 } } +}; () => { - var takesThreeArgs = function(a: number, b: number, c: number) { + function takesThreeArgs(a: number, b: number, c: number) { return [a, b, c]; - }; - takesThreeArgs.length; //=> 3 - takesThreeArgs(1, 2, 3); //=> [1, 2, 3] + } - var takesTwoArgs = R.binary(takesThreeArgs); - takesTwoArgs.length; //=> 2 + takesThreeArgs.length; // => 3 + takesThreeArgs(1, 2, 3); // => [1, 2, 3] + + let takesTwoArgs = R.binary(takesThreeArgs); + takesTwoArgs.length; // => 2 // Only 2 arguments are passed to the wrapped function - takesTwoArgs(1, 2, 3); //=> [1, 2, undefined] -} + takesTwoArgs(1, 2, 3); // => [1, 2, undefined] +}; () => { - var indentN = R.pipe(R.times(R.always(' ')), - R.join(''), - R.replace(/^(?!$)/gm) + let indentN = R.pipe(R.times(R.always(" ")), + R.join(""), + R.replace(/^(?!$)/gm) ); - var format = R.converge( + let format = R.converge( R.call, [ - R.pipe(R.prop('indent'), indentN), - R.prop('value') + R.pipe(R.prop("indent"), indentN), + R.prop("value") ] ); - format({indent: 2, value: 'foo\nbar\nbaz\n'}); //=> ' foo\n bar\n baz\n' -} + format({indent: 2, value: "foo\nbar\nbaz\n"}); // => ' foo\n bar\n baz\n' +}; () => { - type T = {age: number}; - var cmp = R.comparator(function(a: T, b: T) { - return a.age < b.age; - }); - var people = [ - {name: 'Agy', age:33}, {name: 'Bib', age: 15}, {name: 'Cari', age: 16} + interface T { age: number; } + let cmp = R.comparator((a: T, b: T) => a.age < b.age); + let people = [ + {name: "Agy", age: 33}, {name: "Bib", age: 15}, {name: "Cari", age: 16} ]; R.sort(cmp, people); -} +}; () => { - var add = function(a: number, b: number) { return a + b; }; - var multiply = function(a: number, b: number) { return a * b; }; - var subtract = function(a: number, b: number) { return a - b; }; + function add(a: number, b: number) { + return a + b; + } - //≅ multiply( add(1, 2), subtract(1, 2) ); - const x: number = R.converge(multiply, [ add, subtract ])(1, 2); //=> -3 + function multiply(a: number, b: number) { + return a * b; + } - var add3 = function(a: number, b: number, c: number) { return a + b + c; }; - const y: number = R.converge(add3, [ multiply, add, subtract ])(1, 2); //=> 4 -} + function subtract(a: number, b: number) { + return a - b; + } + + // ≅ multiply( add(1, 2), subtract(1, 2) ); + const x: number = R.converge(multiply, [add, subtract])(1, 2); // => -3 + + function add3(a: number, b: number, c: number) { + return a + b + c; + } + + const y: number = R.converge(add3, [multiply, add, subtract])(1, 2); // => 4 +}; () => { - const f0 = R.compose(Math.pow); - const f1 = R.compose(R.negate, Math.pow); - const f2 = R.compose(R.inc, R.negate, Math.pow); - const f3 = R.compose(R.inc, R.inc, R.negate, Math.pow); - const f4 = R.compose(R.inc, R.inc, R.inc, R.negate, Math.pow); - const f5 = R.compose(R.inc, R.inc, R.inc, R.inc, R.negate, Math.pow); + const f0 = R.compose(Math.pow); + const f1 = R.compose(R.negate, Math.pow); + const f2 = R.compose(R.inc, R.negate, Math.pow); + const f3 = R.compose(R.inc, R.inc, R.negate, Math.pow); + const f4 = R.compose(R.inc, R.inc, R.inc, R.negate, Math.pow); + const f5 = R.compose(R.inc, R.inc, R.inc, R.inc, R.negate, Math.pow); const x0: number = f0(3, 4); // -(3^4) + 1 const x1: number = f1(3, 4); // -(3^4) + 1 const x2: number = f2(3, 4); // -(3^4) + 1 const x3: number = f3(3, 4); // -(3^4) + 1 const x4: number = f4(3, 4); // -(3^4) + 1 const x5: number = f5(3, 4); // -(3^4) + 1 -} +}; () => { - const fn = function(a: string, b: number, c: string) { - return [a,b,c]; + function fn(a: string, b: number, c: string) { + return [a, b, c]; } - const gn = R.compose(R.length, fn); - const x: number = gn('Hello', 4, "world"); -} + + const gn = R.compose(R.length, fn); + const x: number = gn("Hello", 4, "world"); +}; (() => { - var Circle = function(r: number) { - this.r = r; + function Circle(r: number) { + this.r = r; this.colors = Array.prototype.slice.call(arguments, 1); - }; - Circle.prototype.area = function() {return Math.PI * Math.pow(this.r, 2);}; - var circleN = R.constructN(2, Circle); - var c1 = circleN(1, 'red'); - var circle = R.construct(Circle); - var c1 = circle(1, 'red'); + } + + Circle.prototype.area = () => Math.PI * Math.pow(this.r, 2); + + let circleN = R.constructN(2, Circle); + let c1 = circleN(1, "red"); + let circle = R.construct(Circle); + c1 = circle(1, "red"); })(); /***************************************************************** * Relation category */ +() => { + let numbers = [1.0, 1.1, 1.2, 2.0, 3.0, 2.2]; + let letters = R.split("", "abcABCaaaBBc"); + R.countBy(Math.floor)(numbers); // => {'1': 3, '2': 2, '3': 1} + R.countBy(R.toLower)(letters); // => {'a': 5, 'b': 4, 'c': 3} +}; () => { - var numbers = [1.0, 1.1, 1.2, 2.0, 3.0, 2.2]; - var letters = R.split('', 'abcABCaaaBBc'); - R.countBy(Math.floor)(numbers); //=> {'1': 3, '2': 2, '3': 1} - R.countBy(R.toLower)(letters); //=> {'a': 5, 'b': 4, 'c': 3} -} + R.difference([1, 2, 3, 4], [7, 6, 5, 4, 3]); // => [1,2] + R.difference([7, 6, 5, 4, 3], [1, 2, 3, 4]); // => [7,6,5] +}; () => { - R.difference([1,2,3,4], [7,6,5,4,3]); //=> [1,2] - R.difference([7,6,5,4,3], [1,2,3,4]); //=> [7,6,5] -} + function cmp(x: any, y: any) { + return x.a === y.a; + } + + let l1 = [{a: 1}, {a: 2}, {a: 3}]; + let l2 = [{a: 3}, {a: 4}]; + R.differenceWith(cmp, l1, l2); // => [{a: 1}, {a: 2}] +}; () => { - function cmp(x: any, y: any) { return x.a === y.a; } - var l1 = [{a: 1}, {a: 2}, {a: 3}]; - var l2 = [{a: 3}, {a: 4}]; - R.differenceWith(cmp, l1, l2); //=> [{a: 1}, {a: 2}] -} + R.equals(1, 1); // => true + R.equals("2", "1"); // => false + R.equals([1, 2, 3], [1, 2, 3]); // => true + + let a: any = {}; + a.v = a; + let b: any = {}; + b.v = b; + R.equals(a, b); // => true +}; () => { - R.equals(1, 1); //=> true - R.equals('2', '1'); //=> false - R.equals([1, 2, 3], [1, 2, 3]); //=> true - - var a: any = {}; a.v = a; - var b: any = {}; b.v = b; - R.equals(a, b); //=> true -} + const a1 = R.identity(1); // => 1 + let obj = {}; + const a2 = R.identity([1, 2, 3]); + const a3 = R.identity(["a", "b", "c"]); + const a4 = R.identity(obj) === obj; // => true +}; () => { - const a1 = R.identity(1); //=> 1 - let obj = {}; - const a2 = R.identity([1,2,3]); - const a3 = R.identity(['a','b','c']); - const a4 = R.identity(obj) === obj; //=> true -} + let o = {}; + R.identical(o, o); // => true + R.identical(1, 1); // => true + R.identical("2", "1"); // => false + R.identical([], []); // => false + R.identical(0, -0); // => false + R.identical(NaN, NaN); // => true +}; () => { - var o = {}; - R.identical(o, o); //=> true - R.identical(1, 1); //=> true - R.identical('2', '1'); //=> false - R.identical([], []); //=> false - R.identical(0, -0); //=> false - R.identical(NaN, NaN); //=> true -} + const testPath = ["x", 0, "y"]; + const testObj = {x: [{y: 2, z: 3}, {y: 4, z: 5}]}; + + R.path(testPath, testObj); // => 2 + R.path(testPath)(testObj); // => 2 +}; () => { - const testPath = ['x', 0, 'y']; - const testObj = {x: [{y: 2, z: 3}, {y: 4, z: 5}]}; - - R.path(testPath, testObj); //=> 2 - R.path(testPath)(testObj); //=> 2 -} - -() => { - var sortByAgeDescending = R.sortBy(R.compose(R.negate, R.prop('age'))); - var alice = { - name: 'ALICE', - age: 101 + let sortByAgeDescending = R.sortBy(R.compose(R.negate, R.prop("age"))); + let alice = { + name: "ALICE", + age : 101 }; - var bob = { - name: 'Bob', - age: -10 + let bob = { + name: "Bob", + age : -10 }; - var clara = { - name: 'clara', - age: 314.159 + let clara = { + name: "clara", + age : 314.159 }; - var people = [clara, bob, alice]; - sortByAgeDescending(people); //=> [alice, bob, clara] -} + let people = [clara, bob, alice]; + sortByAgeDescending(people); // => [alice, bob, clara] +}; () => { - var sortByNameCaseInsensitive = R.sortBy(R.compose(R.toLower, R.prop('name'))); - var alice = { - name: 'ALICE', - age: 101 + let sortByNameCaseInsensitive = R.sortBy(R.compose(R.toLower, R.prop("name"))); + let alice = { + name: "ALICE", + age : 101 }; - var bob = { - name: 'Bob', - age: -10 + let bob = { + name: "Bob", + age : -10 }; - var clara = { - name: 'clara', - age: 314.159 + let clara = { + name: "clara", + age : 314.159 }; - var people = [clara, bob, alice]; - sortByNameCaseInsensitive(people); //=> [alice, bob, clara] -} + let people = [clara, bob, alice]; + sortByNameCaseInsensitive(people); // => [alice, bob, clara] +}; () => { - const a: number[][] = R.splitAt(1, [1, 2, 3]); //=> [[1], [2, 3]] - const b: number[][] = R.splitAt(1)([1, 2, 3]); //=> [[1], [2, 3]] - const c: string[] = R.splitAt(5, 'hello world'); //=> ['hello', ' world'] - const d: string[] = R.splitAt(-1, 'foobar'); //=> ['fooba', 'r'] -} + const a: number[][] = R.splitAt(1, [1, 2, 3]); // => [[1], [2, 3]] + const b: number[][] = R.splitAt(1)([1, 2, 3]); // => [[1], [2, 3]] + const c: string[] = R.splitAt(5, "hello world"); // => ['hello', ' world'] + const d: string[] = R.splitAt(-1, "foobar"); // => ['fooba', 'r'] +}; () => { - const a: number[][] = R.splitWhen(R.equals(2), [1, 2, 3, 1, 2, 3]); //=> [[1], [2, 3, 1, 2, 3]] - const b: number[][] = R.splitWhen(R.equals(2))([1, 2, 3, 1, 2, 3]); //=> [[1], [2, 3, 1, 2, 3]] -} + const a: number[][] = R.splitWhen(R.equals(2), [1, 2, 3, 1, 2, 3]); // => [[1], [2, 3, 1, 2, 3]] + const b: number[][] = R.splitWhen(R.equals(2))([1, 2, 3, 1, 2, 3]); // => [[1], [2, 3, 1, 2, 3]] +}; () => { - R.add(2, 3); //=> 5 - R.add(7)(10); //=> 17 - R.add("Hello", " World"); //=> "Hello World" - R.add("Hello")(" World"); //=> "Hello World" -} + R.add(2, 3); // => 5 + R.add(7)(10); // => 17 + R.add("Hello", " World"); // => "Hello World" + R.add("Hello")(" World"); // => "Hello World" +}; () => { - R.dec(42); //=> 41 -} + R.dec(42); // => 41 +}; () => { - R.divide(71, 100); //=> 0.71 + R.divide(71, 100); // => 0.71 - var half = R.flip(R.divide)(2); - half(42); //=> 21 + let half = R.flip(R.divide)(2); + half(42); // => 21 - var reciprocal = R.divide(1); - reciprocal(4); //=> 0.25 -} + let reciprocal = R.divide(1); + reciprocal(4); // => 0.25 +}; () => { - R.gt(2, 6); //=> false - R.gt(2, 0); //=> true - R.gt(2, 2); //=> false - R.flip(R.gt)(2)(10); //=> true - R.gt(2)(10); //=> false -} + R.gt(2, 6); // => false + R.gt(2, 0); // => true + R.gt(2, 2); // => false + R.flip(R.gt)(2)(10); // => true + R.gt(2)(10); // => false +}; () => { - R.gte(2, 6); //=> false - R.gte(2, 0); //=> true - R.gte(2, 2); //=> false - R.flip(R.gte)(2)(10); //=> true - R.gte(2)(10); //=> false -} + R.gte(2, 6); // => false + R.gte(2, 0); // => true + R.gte(2, 2); // => false + R.flip(R.gte)(2)(10); // => true + R.gte(2)(10); // => false +}; () => { - R.isNaN(NaN); //=> true - R.isNaN(undefined); //=> false - R.isNaN({}); //=> false -} + R.isNaN(NaN); // => true + R.isNaN(undefined); // => false + R.isNaN({}); // => false +}; () => { - R.lt(2, 6); //=> true - R.lt(2, 0); //=> false - R.lt(2, 2); //=> false - R.lt(5)(10); //=> true - R.flip(R.lt)(5)(10); //=> false // right-sectioned currying -} + R.lt(2, 6); // => true + R.lt(2, 0); // => false + R.lt(2, 2); // => false + R.lt(5)(10); // => true + R.flip(R.lt)(5)(10); // => false // right-sectioned currying +}; () => { - R.lte(2, 6); //=> true - R.lte(2, 0); //=> false - R.lte(2, 2); //=> true - R.flip(R.lte)(2)(1); //=> true - R.lte(2)(10); //=> true -} + R.lte(2, 6); // => true + R.lte(2, 0); // => false + R.lte(2, 2); // => true + R.flip(R.lte)(2)(1); // => true + R.lte(2)(10); // => true +}; () => { - R.mathMod(-17, 5); //=> 3 - R.mathMod(17, 5); //=> 2 - R.mathMod(17, -5); //=> NaN - R.mathMod(17, 0); //=> NaN - R.mathMod(17.2, 5); //=> NaN - R.mathMod(17, 5.3); //=> NaN + R.mathMod(-17, 5); // => 3 + R.mathMod(17, 5); // => 2 + R.mathMod(17, -5); // => NaN + R.mathMod(17, 0); // => NaN + R.mathMod(17.2, 5); // => NaN + R.mathMod(17, 5.3); // => NaN - var clock = R.flip(R.mathMod)(12); - clock(15); //=> 3 - clock(24); //=> 0 + let clock = R.flip(R.mathMod)(12); + clock(15); // => 3 + clock(24); // => 0 - var seventeenMod = R.mathMod(17); - seventeenMod(3); //=> 2 -} + let seventeenMod = R.mathMod(17); + seventeenMod(3); // => 2 +}; () => { - var hasName = R.has('name'); - hasName({name: 'alice'}); //=> true - hasName({name: 'bob'}); //=> true - hasName({}); //=> false + let hasName = R.has("name"); + hasName({name: "alice"}); // => true + hasName({name: "bob"}); // => true + hasName({}); // => false - var point = {x: 0, y: 0}; - var pointHas = R.flip(R.has)(point); - pointHas('x'); //=> true - pointHas('y'); //=> true - pointHas('z'); //=> false -} + let point = {x: 0, y: 0}; + let pointHas = R.flip(R.has)(point); + pointHas("x"); // => true + pointHas("y"); // => true + pointHas("z"); // => false +}; () => { - let x: R.Ord = R.max(7, 3); //=> 7 - let y: R.Ord = R.max('a', 'z'); //=> 'z' -} + let x: R.Ord = R.max(7, 3); // => 7 + let y: R.Ord = R.max("a", "z"); // => 'z' +}; () => { - function cmp(obj: { x: R.Ord }) { return obj.x; } - var a = {x: 1}, b = {x: 2}, c = {x: 3}, d = {x: "a"}, e = {x:"z"}; - R.maxBy(cmp, a, c); //=> {x: 3} - R.maxBy(cmp)(a, c); //=> {x: 3} + function cmp(obj: { x: R.Ord }) { + return obj.x; + } + + let a = {x: 1}; + let b = {x: 2}; + let c = {x: 3}; + let d = {x: "a"}; + let e = {x: "z"}; + R.maxBy(cmp, a, c); // => {x: 3} + R.maxBy(cmp)(a, c); // => {x: 3} R.maxBy(cmp)(a)(b); R.maxBy(cmp)(d)(e); -} +}; () => { - const a: number = R.mean([2, 7, 9]); //=> 6 - const b: number = R.mean([]); //=> NaN -} + const a: number = R.mean([2, 7, 9]); // => 6 + const b: number = R.mean([]); // => NaN +}; () => { - const a: number = R.median([7, 2, 10, 9]); //=> 8 - const b: number = R.median([]); //=> NaN -} + const a: number = R.median([7, 2, 10, 9]); // => 8 + const b: number = R.median([]); // => NaN +}; () => { - let x: R.Ord = R.min(9, 3); //=> 3 - let y: R.Ord = R.min('a', 'z'); //=> 'a' -} + let x: R.Ord = R.min(9, 3); // => 3 + let y: R.Ord = R.min("a", "z"); // => 'a' +}; () => { - function cmp(obj: {x: R.Ord}) { return obj.x; } - var a = {x: 1}, b = {x: 2}, c = {x: 3}, d = {x: "a"}, e = {x: "z"}; - R.minBy(cmp, a, b); //=> {x: 1} - R.minBy(cmp)(a, b); //=> {x: 1} + function cmp(obj: { x: R.Ord }) { + return obj.x; + } + + let a = {x: 1}; + let b = {x: 2}; + let c = {x: 3}; + let d = {x: "a"}; + let e = {x: "z"}; + R.minBy(cmp, a, b); // => {x: 1} + R.minBy(cmp)(a, b); // => {x: 1} R.minBy(cmp)(a)(c); R.minBy(cmp, d, e); -} +}; () => { - R.modulo(17, 3); //=> 2 + R.modulo(17, 3); // => 2 // JS behavior: - R.modulo(-17, 3); //=> -2 - R.modulo(17, -3); //=> 2 + R.modulo(-17, 3); // => -2 + R.modulo(17, -3); // => 2 - var isOdd = R.flip(R.modulo)(2); - isOdd(42); //=> 0 - isOdd(21); //=> 1 -} + let isOdd = R.flip(R.modulo)(2); + isOdd(42); // => 0 + isOdd(21); // => 1 +}; () => { - var double = R.multiply(2); - var triple = R.multiply(3); - double(3); //=> 6 - triple(4); //=> 12 - R.multiply(2, 5); //=> 10 -} + let double = R.multiply(2); + let triple = R.multiply(3); + double(3); // => 6 + triple(4); // => 12 + R.multiply(2, 5); // => 10 +}; () => { - R.negate(42); //=> -42 -} + R.negate(42); // => -42 +}; () => { - R.product([2,4,6,8,100,1]); //=> 38400 -} + R.product([2, 4, 6, 8, 100, 1]); // => 38400 +}; () => { - R.subtract(10, 8); //=> 2 + R.subtract(10, 8); // => 2 - var minus5 = R.flip(R.subtract)(5); - minus5(17); //=> 12 + let minus5 = R.flip(R.subtract)(5); + minus5(17); // => 12 - var complementaryAngle = R.subtract(90); - complementaryAngle(30); //=> 60 - complementaryAngle(72); //=> 18 -} + let complementaryAngle = R.subtract(90); + complementaryAngle(30); // => 60 + complementaryAngle(72); // => 18 +}; () => { - R.sum([2,4,6,8,100,1]); //=> 121 -} + R.sum([2, 4, 6, 8, 100, 1]); // => 121 +}; () => { - const a: number[] = R.symmetricDifference([1,2,3,4], [7,6,5,4,3]); //=> [1,2,7,6,5] - const b: number[] = R.symmetricDifference([7,6,5,4,3])([1,2,3,4]); //=> [7,6,5,1,2] -} + const a: number[] = R.symmetricDifference([1, 2, 3, 4], [7, 6, 5, 4, 3]); // => [1,2,7,6,5] + const b: number[] = R.symmetricDifference([7, 6, 5, 4, 3])([1, 2, 3, 4]); // => [7,6,5,1,2] +}; () => { - const eqA = R.eqBy(R.prop('a')); - const l1 = [{a: 1}, {a: 2}, {a: 3}, {a: 4}]; - const l2 = [{a: 3}, {a: 4}, {a: 5}, {a: 6}]; - R.symmetricDifferenceWith(eqA, l1, l2); //=> [{a: 1}, {a: 2}, {a: 5}, {a: 6}] - R.symmetricDifferenceWith(eqA)(l1, l2); //=> [{a: 1}, {a: 2}, {a: 5}, {a: 6}] - const c: (a: any[]) => any[] = R.symmetricDifferenceWith(eqA)(l1); //=> [{a: 1}, {a: 2}, {a: 5}, {a: 6}] -} + const eqA = R.eqBy(R.prop("a")); + const l1 = [{a: 1}, {a: 2}, {a: 3}, {a: 4}]; + const l2 = [{a: 3}, {a: 4}, {a: 5}, {a: 6}]; + R.symmetricDifferenceWith(eqA, l1, l2); // => [{a: 1}, {a: 2}, {a: 5}, {a: 6}] + R.symmetricDifferenceWith(eqA)(l1, l2); // => [{a: 1}, {a: 2}, {a: 5}, {a: 6}] + const c: (a: any[]) => any[] = R.symmetricDifferenceWith(eqA)(l1); // => [{a: 1}, {a: 2}, {a: 5}, {a: 6}] +}; /***************************************************************** * String category */ - () => { - R.replace('foo', 'bar', 'foo foo foo'); //=> 'bar foo foo' - R.replace('foo', 'bar')('foo foo foo'); //=> 'bar foo foo' - R.replace('foo')('bar')('foo foo foo'); //=> 'bar foo foo' - R.replace(/foo/, 'bar', 'foo foo foo'); //=> 'bar foo foo' + R.replace("foo", "bar", "foo foo foo"); // => 'bar foo foo' + R.replace("foo", "bar")("foo foo foo"); // => 'bar foo foo' + R.replace("foo")("bar")("foo foo foo"); // => 'bar foo foo' + R.replace(/foo/, "bar", "foo foo foo"); // => 'bar foo foo' // Use the "g" (global) flag to replace all occurrences: - R.replace(/foo/g, 'bar', 'foo foo foo'); //=> 'bar bar bar' - R.replace(/foo/g, 'bar')('foo foo foo'); //=> 'bar bar bar' - R.replace(/foo/g)('bar')('foo foo foo'); //=> 'bar bar bar' -} + R.replace(/foo/g, "bar", "foo foo foo"); // => 'bar bar bar' + R.replace(/foo/g, "bar")("foo foo foo"); // => 'bar bar bar' + R.replace(/foo/g)("bar")("foo foo foo"); // => 'bar bar bar' +}; /***************************************************************** * Is category */ - () => { - R.is(Object, {}); //=> true - R.is(Object)({}); //=> true - R.is(Number, 1); //=> true - R.is(Number)(1); //=> true - R.is(Object, 1); //=> false - R.is(Object)(1); //=> false - R.is(String, 's'); //=> true - R.is(String)('s'); //=> true - R.is(String, new String('')); //=> true - R.is(String)(new String('')); //=> true - R.is(Object, new String('')); //=> true - R.is(Object)(new String('')); //=> true - R.is(Object, 's'); //=> false - R.is(Object)('s'); //=> false - R.is(Number, {}); //=> false - R.is(Number)({}); //=> false -} + R.is(Object, {}); // => true + R.is(Object)({}); // => true + R.is(Number, 1); // => true + R.is(Number)(1); // => true + R.is(Object, 1); // => false + R.is(Object)(1); // => false + R.is(String, "s"); // => true + R.is(String)("s"); // => true + R.is(String, new String("")); // => true + R.is(String)(new String("")); // => true + R.is(Object, new String("")); // => true + R.is(Object)(new String("")); // => true + R.is(Object, "s"); // => false + R.is(Object)("s"); // => false + R.is(Number, {}); // => false + R.is(Number)({}); // => false +}; /***************************************************************** * Logic category */ () => { - var gt10 = function(x: number) { return x > 10; }; - var even = function(x: number) { return x % 2 === 0}; - var f = R.allPass([gt10, even]); - f(11); //=> false - f(12); //=> true -} + function gt10(x: number) { + return x > 10; + } + + function even(x: number) { + return x % 2 === 0; + } + + let f = R.allPass([gt10, even]); + f(11); // => false + f(12); // => true +}; () => { - R.and(false, true); //=> false - R.and(0, []); //=> 0 - R.and(0)([]); //=> 0 - R.and(null, ''); //=> null - var Why: any = (function(val: boolean) { - var why: any; + R.and(false, true); // => false + R.and(0, []); // => 0 + R.and(0)([]); // => 0 + R.and(null, ""); // => null + let Why: any = ((val: boolean) => { + let why: any; why.val = val; - why.and = function(x: boolean) { - return this.val && x; - } + why.and = (x: boolean) => this.val && x; return Why; })(true); - var why = new Why(true); + let why = new Why(true); R.and(why, false); // false -} -() => { - var gt10 = function(x: number) { return x > 10; }; - var even = function(x: number) { return x % 2 === 0}; - var f = R.anyPass([gt10, even]); - f(11); //=> true - f(8); //=> true - f(9); //=> false -} +}; () => { - var gt10 = function(x: number) { return x > 10; }; - var even = function(x: number) { return x % 2 === 0 }; - var f = R.both(gt10, even); - var g = R.both(gt10)(even); - f(100); //=> true - f(101); //=> false -} + function gt10(x: number) { + return x > 10; + } + + function even(x: number) { + return x % 2 === 0; + } + + let f = R.anyPass([gt10, even]); + f(11); // => true + f(8); // => true + f(9); // => false +}; + () => { - var isEven = function(n: number) { return n % 2 === 0; }; - var isOdd = R.complement(isEven); - isOdd(21); //=> true - isOdd(42); //=> false -} + function gt10(x: number) { + return x > 10; + } + + function even(x: number) { + return x % 2 === 0; + } + + let f = R.both(gt10, even); + let g = R.both(gt10)(even); + f(100); // => true + f(101); // => false +}; + +() => { + function isEven(n: number) { + return n % 2 === 0; + } + + let isOdd = R.complement(isEven); + isOdd(21); // => true + isOdd(42); // => false +}; (() => { - R.eqBy(Math.abs, 5, -5); //=> true + R.eqBy(Math.abs, 5, -5); // => true }); () => { - var defaultTo42 = R.defaultTo(42); - defaultTo42(null); //=> 42 - defaultTo42(undefined); //=> 42 - defaultTo42('Ramda'); //=> 'Ramda' -} + let defaultTo42 = R.defaultTo(42); + defaultTo42(null); // => 42 + defaultTo42(undefined); // => 42 + defaultTo42("Ramda"); // => 'Ramda' +}; + () => { - var gt10 = function(x: number) { return x > 10; }; - var even = function(x: number) { return x % 2 === 0 }; - var f = R.either(gt10, even); - var g = R.either(gt10)(even); - f(101); //=> true - f(8); //=> true -} + function gt10(x: number) { + return x > 10; + } + + function even(x: number) { + return x % 2 === 0; + } + + let f = R.either(gt10, even); + let g = R.either(gt10)(even); + f(101); // => true + f(8); // => true +}; + () => { // Flatten all arrays in the list but leave other values alone. - var flattenArrays = R.map(R.ifElse(Array.isArray, R.flatten, R.identity)); + let flattenArrays = R.map(R.ifElse(Array.isArray, R.flatten, R.identity)); - flattenArrays([[0], [[10], [8]], 1234, {}]); //=> [[0], [10, 8], 1234, {}] - flattenArrays([[[10], 123], [8, [10]], "hello"]); //=> [[10, 123], [8, 10], "hello"] -} -() => { - R.isEmpty([1, 2, 3]); //=> false - R.isEmpty([]); //=> true - R.isEmpty(''); //=> true - R.isEmpty(null); //=> false - R.isEmpty({}); //=>true - R.isEmpty({a:1}); //=> false -} + flattenArrays([[0], [[10], [8]], 1234, {}]); // => [[0], [10, 8], 1234, {}] + flattenArrays([[[10], 123], [8, [10]], "hello"]); // => [[10, 123], [8, 10], "hello"] +}; () => { - R.not(true); //=> false - R.not(false); //=> true + R.isEmpty([1, 2, 3]); // => false + R.isEmpty([]); // => true + R.isEmpty(""); // => true + R.isEmpty(null); // => false + R.isEmpty({}); // =>true + R.isEmpty({a: 1}); // => false +}; + +() => { + R.not(true); // => false + R.not(false); // => true R.not(0); // => true R.not(1); // => false -} +}; class Why { val: boolean; + constructor(val: boolean) { this.val = val; } + or(x: boolean) { return this.val && x; } } () => { - const x0: boolean = R.or(false, true); //=> false - const x1: number|any[] = R.or(0, []); //=> [] - const x2: number|any[] = R.or(0)([]); //=> [] - const x3: string = R.or(null, ''); //=> '' + const x0: boolean = R.or(false, true); // => false + const x1: number | any[] = R.or(0, []); // => [] + const x2: number | any[] = R.or(0)([]); // => [] + const x3: string = R.or(null, ""); // => '' - var why = new Why(true); - why.or(true) - const x4: Why|boolean = R.or(why, false); // false -} + let why = new Why(true); + why.or(true); + const x4: Why | boolean = R.or(why, false); // false +}; () => { - R.intersperse(',', ['foo', 'bar']); //=> ['foo', ',', 'bar'] - R.intersperse(0, [1, 2]); //=> [1, 0, 2] - R.intersperse(0, [1]); //=> [1] -} + R.intersperse(",", ["foo", "bar"]); // => ['foo', ',', 'bar'] + 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) + }; + R.map(x => x.trim(), functor); } diff --git a/types/ramda/tslint.json b/types/ramda/tslint.json new file mode 100644 index 0000000000..6356421ec0 --- /dev/null +++ b/types/ramda/tslint.json @@ -0,0 +1,6 @@ +{ + "extends": "dtslint/dt.json", + "rules": { + "no-construct": false // Required for R.is function testing + } +}