space-lift
Advanced tools
Comparing version 0.4.3 to 0.4.4
@@ -8,4 +8,13 @@ import { Option } from '../option'; | ||
} | ||
/** | ||
* Maps this Array to an Array of Array | Option | ArrayOps using a mapper function then flattens it. | ||
*/ | ||
export declare function flatMap<A, B>(this: ArrayOps<A>, fun: (item: A, index: number) => B[]): ArrayOps<B>; | ||
/** | ||
* Maps this Array to an Array of Array | Option | ArrayOps using a mapper function then flattens it. | ||
*/ | ||
export declare function flatMap<A, B>(this: ArrayOps<A>, fun: (item: A, index: number) => ArrayOps<B>): ArrayOps<B>; | ||
/** | ||
* Maps this Array to an Array of Array | Option | ArrayOps using a mapper function then flattens it. | ||
*/ | ||
export declare function flatMap<A, B>(this: ArrayOps<A>, fun: (item: A, index: number) => Option<B>): ArrayOps<B>; |
@@ -1,2 +0,2 @@ | ||
import { ArrayOps, ObjectOps, NumberOps, StringOps, BoolOps } from '../lift'; | ||
import { ArrayOps, ObjectOps, NumberOps, StringOps, BoolOps, DateOps } from '../lift'; | ||
declare module '../../wrapper' { | ||
@@ -7,6 +7,25 @@ interface ArrayOps<A> { | ||
} | ||
/** | ||
* Folds this Array into a single value, using a starting value. | ||
*/ | ||
export declare function fold<A>(this: ArrayOps<A>, startValue: number, func: (acc: number, value: A, index: number) => number): NumberOps; | ||
/** | ||
* Folds this Array into a single value, using a starting value. | ||
*/ | ||
export declare function fold<A>(this: ArrayOps<A>, startValue: string, func: (acc: string, value: A, index: number) => string): StringOps; | ||
/** | ||
* Folds this Array into a single value, using a starting value. | ||
*/ | ||
export declare function fold<A>(this: ArrayOps<A>, startValue: boolean, func: (acc: boolean, value: A, index: number) => boolean): BoolOps; | ||
/** | ||
* Folds this Array into a single value, using a starting value. | ||
*/ | ||
export declare function fold<A, B>(this: ArrayOps<A>, startValue: B[], func: (acc: B[], value: A, index: number) => B[]): ArrayOps<B>; | ||
/** | ||
* Folds this Array into a single value, using a starting value. | ||
*/ | ||
export declare function fold<A, B>(this: ArrayOps<A>, startValue: Date, func: (acc: Date, value: A, index: number) => Date): DateOps; | ||
/** | ||
* Folds this Array into a single value, using a starting value. | ||
*/ | ||
export declare function fold<A, B>(this: ArrayOps<A>, startValue: B, func: (acc: B, value: A, index: number) => B): ObjectOps<B>; |
@@ -1,2 +0,2 @@ | ||
import { ArrayOps, ObjectOps, NumberOps, StringOps, BoolOps } from '../lift'; | ||
import { ArrayOps, ObjectOps, NumberOps, StringOps, BoolOps, DateOps } from '../lift'; | ||
declare module '../../wrapper' { | ||
@@ -7,6 +7,25 @@ interface ArrayOps<A> { | ||
} | ||
/** | ||
* Folds this Array into a single value, using a starting value, from the right. | ||
*/ | ||
export declare function foldRight<A>(this: ArrayOps<A>, startValue: number, func: (acc: number, value: A, index: number) => number): NumberOps; | ||
/** | ||
* Folds this Array into a single value, using a starting value, from the right. | ||
*/ | ||
export declare function foldRight<A>(this: ArrayOps<A>, startValue: string, func: (acc: string, value: A, index: number) => string): StringOps; | ||
/** | ||
* Folds this Array into a single value, using a starting value, from the right. | ||
*/ | ||
export declare function foldRight<A>(this: ArrayOps<A>, startValue: boolean, func: (acc: boolean, value: A, index: number) => boolean): BoolOps; | ||
/** | ||
* Folds this Array into a single value, using a starting value, from the right. | ||
*/ | ||
export declare function foldRight<A, B>(this: ArrayOps<A>, startValue: Date, func: (acc: B, value: A, index: number) => Date): DateOps; | ||
/** | ||
* Folds this Array into a single value, using a starting value, from the right. | ||
*/ | ||
export declare function foldRight<A, B>(this: ArrayOps<A>, startValue: B[], func: (acc: B[], value: A, index: number) => B[]): ArrayOps<B>; | ||
/** | ||
* Folds this Array into a single value, using a starting value, from the right. | ||
*/ | ||
export declare function foldRight<A, B>(this: ArrayOps<A>, startValue: B, func: (acc: B, value: A, index: number) => B): ObjectOps<B>; |
@@ -7,3 +7,9 @@ import { ArrayOps, Wrapper } from '../lift'; | ||
} | ||
/** | ||
* Maps this Array using a mapper function. | ||
*/ | ||
export declare function map<A, B>(this: ArrayOps<A>, fun: (item: A, index: number) => B | Wrapper<B>): ArrayOps<B>; | ||
/** | ||
* Maps this Array using a mapper function. | ||
*/ | ||
export declare function map<A, B>(this: ArrayOps<A>, fun: (item: A, index: number) => B): ArrayOps<B>; |
@@ -7,7 +7,13 @@ import { ArrayOps, ObjectOps } from '../lift'; | ||
} | ||
/** | ||
* Converts this Array of numbers or strings to a Set-like object where values are all truthy. | ||
*/ | ||
export declare function toSet(this: ArrayOps<string>): ObjectOps<{ | ||
[key: string]: boolean; | ||
}>; | ||
/** | ||
* Converts this Array of numbers or strings to a Set-like object where values are all truthy. | ||
*/ | ||
export declare function toSet(this: ArrayOps<number>): ObjectOps<{ | ||
[key: number]: boolean; | ||
}>; |
@@ -7,3 +7,9 @@ import { ArrayOps, Wrapper } from '../lift'; | ||
} | ||
/** | ||
* Updates an item at the specified index. | ||
*/ | ||
export declare function updateAt<A>(this: ArrayOps<A>, index: number, updater: (item: A) => Wrapper<A>): ArrayOps<A>; | ||
/** | ||
* Updates an item at the specified index. | ||
*/ | ||
export declare function updateAt<A>(this: ArrayOps<A>, index: number, updater: (item: A) => A): ArrayOps<A>; |
import lift from './lift'; | ||
export default lift; | ||
export { ArrayOps, ObjectOps, BoolOps, NumberOps, StringOps, Wrapper, getValue } from './lift'; | ||
export { ArrayOps, ObjectOps, BoolOps, NumberOps, StringOps, DateOps, Wrapper, getValue } from './lift'; | ||
export { update, deepUpdate, DELETE } from 'immupdate'; | ||
@@ -5,0 +5,0 @@ export { Option, None, Some } from './option'; |
@@ -11,2 +11,3 @@ "use strict"; | ||
exports.StringOps = lift_2.StringOps; | ||
exports.DateOps = lift_2.DateOps; | ||
exports.getValue = lift_2.getValue; | ||
@@ -13,0 +14,0 @@ var immupdate_1 = require("immupdate"); |
@@ -1,2 +0,2 @@ | ||
import { Wrapper, ArrayOpsConstructor, ArrayOps as IArrayOps, ObjectOpsConstructor, ObjectOps as IObjectOps, NumberOpsConstructor, NumberOps as INumberOps, StringOpsConstructor, StringOps as IStringOps, BoolOpsConstructor, BoolOps as IBoolOps } from '../wrapper'; | ||
import { Wrapper, ArrayOpsConstructor, ArrayOps as IArrayOps, ObjectOpsConstructor, ObjectOps as IObjectOps, NumberOpsConstructor, NumberOps as INumberOps, StringOpsConstructor, StringOps as IStringOps, BoolOpsConstructor, BoolOps as IBoolOps, DateOpsConstructor, DateOps as IDateOps } from '../wrapper'; | ||
export { Wrapper } from '../wrapper'; | ||
@@ -10,2 +10,4 @@ export interface Lift { | ||
(obj: boolean): BoolOps; | ||
/** Wraps a Date to provide a richer API. Unwrap with .value() **/ | ||
(obj: Date): DateOps; | ||
/** Wraps an Array to provide a richer API. Unwrap with .value() **/ | ||
@@ -27,3 +29,5 @@ <T>(obj: T[]): ArrayOps<T>; | ||
export declare const StringOps: StringOpsConstructor; | ||
export declare type DateOps = IDateOps; | ||
export declare const DateOps: DateOpsConstructor; | ||
export declare type BoolOps = IBoolOps; | ||
export declare const BoolOps: BoolOpsConstructor; |
@@ -6,2 +6,4 @@ "use strict"; | ||
return new exports.ArrayOps(obj); | ||
if (obj instanceof Date) | ||
return new exports.DateOps(obj); | ||
if (typeof obj === 'string') | ||
@@ -37,2 +39,3 @@ return new exports.StringOps(obj); | ||
exports.StringOps = makeOps(); | ||
exports.DateOps = makeOps(); | ||
exports.BoolOps = makeOps(); |
@@ -5,6 +5,9 @@ /** Returns whether an object is an Array */ | ||
export declare function func(obj: {}): obj is Function; | ||
/** Returns whether this object is a string */ | ||
export declare function string(obj: {}): obj is string; | ||
/** Returns whether this object is a number */ | ||
export declare function number(obj: {}): obj is number; | ||
/** Returns whether this object is a boolean */ | ||
export declare function boolean(obj: {}): obj is boolean; | ||
/** Returns whether this value is an object (e.g not a primitive: arrays, functions, objects, regexes, `new Number(0)`, and `new String('')) */ | ||
/** Returns whether this value is an object (e.g not a primitive: dates, arrays, functions, objects, regexes, `new Number(0)`, and `new String('')) */ | ||
export declare function object(obj: {}): obj is object; |
@@ -10,2 +10,3 @@ "use strict"; | ||
exports.func = func; | ||
/** Returns whether this object is a string */ | ||
function string(obj) { | ||
@@ -15,2 +16,3 @@ return (typeof obj === 'string'); | ||
exports.string = string; | ||
/** Returns whether this object is a number */ | ||
function number(obj) { | ||
@@ -20,2 +22,3 @@ return (typeof obj === 'number'); | ||
exports.number = number; | ||
/** Returns whether this object is a boolean */ | ||
function boolean(obj) { | ||
@@ -25,3 +28,3 @@ return (typeof obj === 'boolean'); | ||
exports.boolean = boolean; | ||
/** Returns whether this value is an object (e.g not a primitive: arrays, functions, objects, regexes, `new Number(0)`, and `new String('')) */ | ||
/** Returns whether this value is an object (e.g not a primitive: dates, arrays, functions, objects, regexes, `new Number(0)`, and `new String('')) */ | ||
function object(obj) { | ||
@@ -28,0 +31,0 @@ var type = typeof obj; |
@@ -17,3 +17,11 @@ import { Wrapper, ArrayOps } from '../lift'; | ||
forEach(fn: (a: A) => void): void; | ||
/** | ||
* Maps the value contained in this Some, else returns None. | ||
* Depending on the map function return value, a Some could be tranformed into a None. | ||
*/ | ||
map<B>(fn: (a: A) => Wrapper<B> | null | undefined): Option<B>; | ||
/** | ||
* Maps the value contained in this Some, else returns None. | ||
* Depending on the map function return value, a Some could be tranformed into a None. | ||
*/ | ||
map<B>(fn: (a: A) => B | null | undefined): Option<B>; | ||
@@ -77,5 +85,21 @@ /** | ||
all<T1, T2>(t1: NullableValue<T1>, t2: NullableValue<T2>): Option<[T1, T2]>; | ||
/** | ||
* Creates a new Option holding the tuple of all the passed values if they were all Some or non null/undefined values, | ||
* else returns None | ||
*/ | ||
all<T1, T2, T3>(t1: NullableValue<T1>, t2: NullableValue<T2>, t3: NullableValue<T3>): Option<[T1, T2, T3]>; | ||
/** | ||
* Creates a new Option holding the tuple of all the passed values if they were all Some or non null/undefined values, | ||
* else returns None | ||
*/ | ||
all<T1, T2, T3, T4>(t1: NullableValue<T1>, t2: NullableValue<T2>, t3: NullableValue<T3>, t4: NullableValue<T4>): Option<[T1, T2, T3, T4]>; | ||
/** | ||
* Creates a new Option holding the tuple of all the passed values if they were all Some or non null/undefined values, | ||
* else returns None | ||
*/ | ||
all<T1, T2, T3, T4, T5>(t1: NullableValue<T1>, t2: NullableValue<T2>, t3: NullableValue<T3>, t4: NullableValue<T4>, t5: NullableValue<T5>): Option<[T1, T2, T3, T4, T5]>; | ||
/** | ||
* Creates a new Option holding the tuple of all the passed values if they were all Some or non null/undefined values, | ||
* else returns None | ||
*/ | ||
all<T>(...ts: Array<NullableValue<T>>): Option<T[]>; | ||
@@ -82,0 +106,0 @@ } |
@@ -36,4 +36,16 @@ import { Wrapper } from '../lift'; | ||
all<A, B, E1, E2>(a: Result<E1, A>, b: Result<E2, B>): Result<E1 | E2, [A, B]>; | ||
/** | ||
* Creates a new Ok Result holding the tuple of all the passed values if they were all Ok, | ||
* else returns the first encountered Err. | ||
*/ | ||
all<A, B, C, E1, E2, E3>(a: Result<E1, A>, b: Result<E2, B>, c: Result<E3, C>): Result<E1 | E2 | E3, [A, B, C]>; | ||
/** | ||
* Creates a new Ok Result holding the tuple of all the passed values if they were all Ok, | ||
* else returns the first encountered Err. | ||
*/ | ||
all<A, B, C, D, E1, E2, E3, E4>(a: Result<E1, A>, b: Result<E2, B>, c: Result<E3, C>, d: Result<E4, D>): Result<E1 | E2 | E3 | E4, [A, B, C, D]>; | ||
/** | ||
* Creates a new Ok Result holding the tuple of all the passed values if they were all Ok, | ||
* else returns the first encountered Err. | ||
*/ | ||
all<A, E>(...results: Result<E, A>[]): Result<E, A[]>; | ||
@@ -40,0 +52,0 @@ } |
@@ -1,2 +0,2 @@ | ||
import { ArrayOps, ObjectOps, NumberOps, StringOps, BoolOps, Wrapper } from './lift'; | ||
import { ArrayOps, ObjectOps, NumberOps, StringOps, DateOps, BoolOps, Wrapper } from './lift'; | ||
declare module '../wrapper' { | ||
@@ -23,2 +23,7 @@ interface ArrayOps<A> { | ||
declare module '../wrapper' { | ||
interface DateOps { | ||
transform: typeof transform; | ||
} | ||
} | ||
declare module '../wrapper' { | ||
interface BoolOps { | ||
@@ -28,6 +33,49 @@ transform: typeof transform; | ||
} | ||
/** | ||
* Runs an arbitrary function to transform this wrapper into a Number wrapper | ||
*/ | ||
export declare function transform<A>(this: Wrapper<A>, func: (source: A) => number): NumberOps; | ||
/** | ||
* Runs an arbitrary function to transform this wrapper into a number wrapper | ||
*/ | ||
export declare function transform<A>(this: Wrapper<A>, func: (source: A) => NumberOps): NumberOps; | ||
/** | ||
* Runs an arbitrary function to transform this wrapper into a string wrapper | ||
*/ | ||
export declare function transform<A>(this: Wrapper<A>, func: (source: A) => string): StringOps; | ||
/** | ||
* Runs an arbitrary function to transform this wrapper into a string wrapper | ||
*/ | ||
export declare function transform<A>(this: Wrapper<A>, func: (source: A) => StringOps): StringOps; | ||
/** | ||
* Runs an arbitrary function to transform this wrapper into a boolean wrapper | ||
*/ | ||
export declare function transform<A>(this: Wrapper<A>, func: (source: A) => boolean): BoolOps; | ||
/** | ||
* Runs an arbitrary function to transform this wrapper into a boolean wrapper | ||
*/ | ||
export declare function transform<A>(this: Wrapper<A>, func: (source: A) => BoolOps): BoolOps; | ||
/** | ||
* Runs an arbitrary function to transform this wrapper into a date wrapper | ||
*/ | ||
export declare function transform<A>(this: Wrapper<A>, func: (source: A) => Date): DateOps; | ||
/** | ||
* Runs an arbitrary function to transform this wrapper into a date wrapper | ||
*/ | ||
export declare function transform<A>(this: Wrapper<A>, func: (source: A) => DateOps): DateOps; | ||
/** | ||
* Runs an arbitrary function to transform this wrapper into a array wrapper | ||
*/ | ||
export declare function transform<A, B>(this: Wrapper<A>, func: (source: A) => B[]): ArrayOps<B>; | ||
/** | ||
* Runs an arbitrary function to transform this wrapper into a array wrapper | ||
*/ | ||
export declare function transform<A, B>(this: Wrapper<A>, func: (source: A) => ArrayOps<B>): ArrayOps<B>; | ||
/** | ||
* Runs an arbitrary function to transform this wrapper into an object wrapper | ||
*/ | ||
export declare function transform<A, B>(this: Wrapper<A>, func: (source: A) => B): ObjectOps<B>; | ||
/** | ||
* Runs an arbitrary function to transform this wrapper into an object wrapper | ||
*/ | ||
export declare function transform<A, B>(this: Wrapper<A>, func: (source: A) => ObjectOps<B>): ObjectOps<B>; |
"use strict"; | ||
exports.__esModule = true; | ||
var lift_1 = require("./lift"); | ||
/** | ||
* Runs an arbitrary transformation. | ||
*/ | ||
function transform(func) { | ||
return lift_1["default"](func(this.value())); | ||
return lift_1["default"](lift_1.getValue(func(this.value()))); | ||
} | ||
@@ -16,1 +13,2 @@ exports.transform = transform; | ||
lift_1.ObjectOps.prototype.transform = transform; | ||
lift_1.DateOps.prototype.transform = transform; |
@@ -8,4 +8,13 @@ import { Option } from '../option'; | ||
} | ||
/** | ||
* Maps this Array to an Array of Array | Option | ArrayOps using a mapper function then flattens it. | ||
*/ | ||
export declare function flatMap<A, B>(this: ArrayOps<A>, fun: (item: A, index: number) => B[]): ArrayOps<B>; | ||
/** | ||
* Maps this Array to an Array of Array | Option | ArrayOps using a mapper function then flattens it. | ||
*/ | ||
export declare function flatMap<A, B>(this: ArrayOps<A>, fun: (item: A, index: number) => ArrayOps<B>): ArrayOps<B>; | ||
/** | ||
* Maps this Array to an Array of Array | Option | ArrayOps using a mapper function then flattens it. | ||
*/ | ||
export declare function flatMap<A, B>(this: ArrayOps<A>, fun: (item: A, index: number) => Option<B>): ArrayOps<B>; |
@@ -1,2 +0,2 @@ | ||
import { ArrayOps, ObjectOps, NumberOps, StringOps, BoolOps } from '../lift'; | ||
import { ArrayOps, ObjectOps, NumberOps, StringOps, BoolOps, DateOps } from '../lift'; | ||
declare module '../../wrapper' { | ||
@@ -7,6 +7,25 @@ interface ArrayOps<A> { | ||
} | ||
/** | ||
* Folds this Array into a single value, using a starting value. | ||
*/ | ||
export declare function fold<A>(this: ArrayOps<A>, startValue: number, func: (acc: number, value: A, index: number) => number): NumberOps; | ||
/** | ||
* Folds this Array into a single value, using a starting value. | ||
*/ | ||
export declare function fold<A>(this: ArrayOps<A>, startValue: string, func: (acc: string, value: A, index: number) => string): StringOps; | ||
/** | ||
* Folds this Array into a single value, using a starting value. | ||
*/ | ||
export declare function fold<A>(this: ArrayOps<A>, startValue: boolean, func: (acc: boolean, value: A, index: number) => boolean): BoolOps; | ||
/** | ||
* Folds this Array into a single value, using a starting value. | ||
*/ | ||
export declare function fold<A, B>(this: ArrayOps<A>, startValue: B[], func: (acc: B[], value: A, index: number) => B[]): ArrayOps<B>; | ||
/** | ||
* Folds this Array into a single value, using a starting value. | ||
*/ | ||
export declare function fold<A, B>(this: ArrayOps<A>, startValue: Date, func: (acc: Date, value: A, index: number) => Date): DateOps; | ||
/** | ||
* Folds this Array into a single value, using a starting value. | ||
*/ | ||
export declare function fold<A, B>(this: ArrayOps<A>, startValue: B, func: (acc: B, value: A, index: number) => B): ObjectOps<B>; |
@@ -1,2 +0,2 @@ | ||
import { ArrayOps, ObjectOps, NumberOps, StringOps, BoolOps } from '../lift'; | ||
import { ArrayOps, ObjectOps, NumberOps, StringOps, BoolOps, DateOps } from '../lift'; | ||
declare module '../../wrapper' { | ||
@@ -7,6 +7,25 @@ interface ArrayOps<A> { | ||
} | ||
/** | ||
* Folds this Array into a single value, using a starting value, from the right. | ||
*/ | ||
export declare function foldRight<A>(this: ArrayOps<A>, startValue: number, func: (acc: number, value: A, index: number) => number): NumberOps; | ||
/** | ||
* Folds this Array into a single value, using a starting value, from the right. | ||
*/ | ||
export declare function foldRight<A>(this: ArrayOps<A>, startValue: string, func: (acc: string, value: A, index: number) => string): StringOps; | ||
/** | ||
* Folds this Array into a single value, using a starting value, from the right. | ||
*/ | ||
export declare function foldRight<A>(this: ArrayOps<A>, startValue: boolean, func: (acc: boolean, value: A, index: number) => boolean): BoolOps; | ||
/** | ||
* Folds this Array into a single value, using a starting value, from the right. | ||
*/ | ||
export declare function foldRight<A, B>(this: ArrayOps<A>, startValue: Date, func: (acc: B, value: A, index: number) => Date): DateOps; | ||
/** | ||
* Folds this Array into a single value, using a starting value, from the right. | ||
*/ | ||
export declare function foldRight<A, B>(this: ArrayOps<A>, startValue: B[], func: (acc: B[], value: A, index: number) => B[]): ArrayOps<B>; | ||
/** | ||
* Folds this Array into a single value, using a starting value, from the right. | ||
*/ | ||
export declare function foldRight<A, B>(this: ArrayOps<A>, startValue: B, func: (acc: B, value: A, index: number) => B): ObjectOps<B>; |
@@ -7,3 +7,9 @@ import { ArrayOps, Wrapper } from '../lift'; | ||
} | ||
/** | ||
* Maps this Array using a mapper function. | ||
*/ | ||
export declare function map<A, B>(this: ArrayOps<A>, fun: (item: A, index: number) => B | Wrapper<B>): ArrayOps<B>; | ||
/** | ||
* Maps this Array using a mapper function. | ||
*/ | ||
export declare function map<A, B>(this: ArrayOps<A>, fun: (item: A, index: number) => B): ArrayOps<B>; |
@@ -7,7 +7,13 @@ import { ArrayOps, ObjectOps } from '../lift'; | ||
} | ||
/** | ||
* Converts this Array of numbers or strings to a Set-like object where values are all truthy. | ||
*/ | ||
export declare function toSet(this: ArrayOps<string>): ObjectOps<{ | ||
[key: string]: boolean; | ||
}>; | ||
/** | ||
* Converts this Array of numbers or strings to a Set-like object where values are all truthy. | ||
*/ | ||
export declare function toSet(this: ArrayOps<number>): ObjectOps<{ | ||
[key: number]: boolean; | ||
}>; |
@@ -7,3 +7,9 @@ import { ArrayOps, Wrapper } from '../lift'; | ||
} | ||
/** | ||
* Updates an item at the specified index. | ||
*/ | ||
export declare function updateAt<A>(this: ArrayOps<A>, index: number, updater: (item: A) => Wrapper<A>): ArrayOps<A>; | ||
/** | ||
* Updates an item at the specified index. | ||
*/ | ||
export declare function updateAt<A>(this: ArrayOps<A>, index: number, updater: (item: A) => A): ArrayOps<A>; |
import lift from './lift'; | ||
export default lift; | ||
export { ArrayOps, ObjectOps, BoolOps, NumberOps, StringOps, Wrapper, getValue } from './lift'; | ||
export { ArrayOps, ObjectOps, BoolOps, NumberOps, StringOps, DateOps, Wrapper, getValue } from './lift'; | ||
export { update, deepUpdate, DELETE } from 'immupdate'; | ||
@@ -5,0 +5,0 @@ export { Option, None, Some } from './option'; |
import lift from './lift'; | ||
export default lift; | ||
export { ArrayOps, ObjectOps, BoolOps, NumberOps, StringOps, getValue } from './lift'; | ||
export { ArrayOps, ObjectOps, BoolOps, NumberOps, StringOps, DateOps, getValue } from './lift'; | ||
export { update, deepUpdate, DELETE } from 'immupdate'; | ||
@@ -5,0 +5,0 @@ export { Option, None, Some } from './option'; |
@@ -1,2 +0,2 @@ | ||
import { Wrapper, ArrayOpsConstructor, ArrayOps as IArrayOps, ObjectOpsConstructor, ObjectOps as IObjectOps, NumberOpsConstructor, NumberOps as INumberOps, StringOpsConstructor, StringOps as IStringOps, BoolOpsConstructor, BoolOps as IBoolOps } from '../wrapper'; | ||
import { Wrapper, ArrayOpsConstructor, ArrayOps as IArrayOps, ObjectOpsConstructor, ObjectOps as IObjectOps, NumberOpsConstructor, NumberOps as INumberOps, StringOpsConstructor, StringOps as IStringOps, BoolOpsConstructor, BoolOps as IBoolOps, DateOpsConstructor, DateOps as IDateOps } from '../wrapper'; | ||
export { Wrapper } from '../wrapper'; | ||
@@ -10,2 +10,4 @@ export interface Lift { | ||
(obj: boolean): BoolOps; | ||
/** Wraps a Date to provide a richer API. Unwrap with .value() **/ | ||
(obj: Date): DateOps; | ||
/** Wraps an Array to provide a richer API. Unwrap with .value() **/ | ||
@@ -27,3 +29,5 @@ <T>(obj: T[]): ArrayOps<T>; | ||
export declare const StringOps: StringOpsConstructor; | ||
export declare type DateOps = IDateOps; | ||
export declare const DateOps: DateOpsConstructor; | ||
export declare type BoolOps = IBoolOps; | ||
export declare const BoolOps: BoolOpsConstructor; |
var lift = function (obj) { | ||
if (obj instanceof Array) | ||
return new ArrayOps(obj); | ||
if (obj instanceof Date) | ||
return new DateOps(obj); | ||
if (typeof obj === 'string') | ||
@@ -33,2 +35,3 @@ return new StringOps(obj); | ||
export var StringOps = makeOps(); | ||
export var DateOps = makeOps(); | ||
export var BoolOps = makeOps(); |
@@ -5,6 +5,9 @@ /** Returns whether an object is an Array */ | ||
export declare function func(obj: {}): obj is Function; | ||
/** Returns whether this object is a string */ | ||
export declare function string(obj: {}): obj is string; | ||
/** Returns whether this object is a number */ | ||
export declare function number(obj: {}): obj is number; | ||
/** Returns whether this object is a boolean */ | ||
export declare function boolean(obj: {}): obj is boolean; | ||
/** Returns whether this value is an object (e.g not a primitive: arrays, functions, objects, regexes, `new Number(0)`, and `new String('')) */ | ||
/** Returns whether this value is an object (e.g not a primitive: dates, arrays, functions, objects, regexes, `new Number(0)`, and `new String('')) */ | ||
export declare function object(obj: {}): obj is object; |
@@ -7,12 +7,15 @@ /** Returns whether an object is an Array */ | ||
} | ||
/** Returns whether this object is a string */ | ||
export function string(obj) { | ||
return (typeof obj === 'string'); | ||
} | ||
/** Returns whether this object is a number */ | ||
export function number(obj) { | ||
return (typeof obj === 'number'); | ||
} | ||
/** Returns whether this object is a boolean */ | ||
export function boolean(obj) { | ||
return (typeof obj === 'boolean'); | ||
} | ||
/** Returns whether this value is an object (e.g not a primitive: arrays, functions, objects, regexes, `new Number(0)`, and `new String('')) */ | ||
/** Returns whether this value is an object (e.g not a primitive: dates, arrays, functions, objects, regexes, `new Number(0)`, and `new String('')) */ | ||
export function object(obj) { | ||
@@ -19,0 +22,0 @@ var type = typeof obj; |
@@ -17,3 +17,11 @@ import { Wrapper, ArrayOps } from '../lift'; | ||
forEach(fn: (a: A) => void): void; | ||
/** | ||
* Maps the value contained in this Some, else returns None. | ||
* Depending on the map function return value, a Some could be tranformed into a None. | ||
*/ | ||
map<B>(fn: (a: A) => Wrapper<B> | null | undefined): Option<B>; | ||
/** | ||
* Maps the value contained in this Some, else returns None. | ||
* Depending on the map function return value, a Some could be tranformed into a None. | ||
*/ | ||
map<B>(fn: (a: A) => B | null | undefined): Option<B>; | ||
@@ -77,5 +85,21 @@ /** | ||
all<T1, T2>(t1: NullableValue<T1>, t2: NullableValue<T2>): Option<[T1, T2]>; | ||
/** | ||
* Creates a new Option holding the tuple of all the passed values if they were all Some or non null/undefined values, | ||
* else returns None | ||
*/ | ||
all<T1, T2, T3>(t1: NullableValue<T1>, t2: NullableValue<T2>, t3: NullableValue<T3>): Option<[T1, T2, T3]>; | ||
/** | ||
* Creates a new Option holding the tuple of all the passed values if they were all Some or non null/undefined values, | ||
* else returns None | ||
*/ | ||
all<T1, T2, T3, T4>(t1: NullableValue<T1>, t2: NullableValue<T2>, t3: NullableValue<T3>, t4: NullableValue<T4>): Option<[T1, T2, T3, T4]>; | ||
/** | ||
* Creates a new Option holding the tuple of all the passed values if they were all Some or non null/undefined values, | ||
* else returns None | ||
*/ | ||
all<T1, T2, T3, T4, T5>(t1: NullableValue<T1>, t2: NullableValue<T2>, t3: NullableValue<T3>, t4: NullableValue<T4>, t5: NullableValue<T5>): Option<[T1, T2, T3, T4, T5]>; | ||
/** | ||
* Creates a new Option holding the tuple of all the passed values if they were all Some or non null/undefined values, | ||
* else returns None | ||
*/ | ||
all<T>(...ts: Array<NullableValue<T>>): Option<T[]>; | ||
@@ -82,0 +106,0 @@ } |
@@ -36,4 +36,16 @@ import { Wrapper } from '../lift'; | ||
all<A, B, E1, E2>(a: Result<E1, A>, b: Result<E2, B>): Result<E1 | E2, [A, B]>; | ||
/** | ||
* Creates a new Ok Result holding the tuple of all the passed values if they were all Ok, | ||
* else returns the first encountered Err. | ||
*/ | ||
all<A, B, C, E1, E2, E3>(a: Result<E1, A>, b: Result<E2, B>, c: Result<E3, C>): Result<E1 | E2 | E3, [A, B, C]>; | ||
/** | ||
* Creates a new Ok Result holding the tuple of all the passed values if they were all Ok, | ||
* else returns the first encountered Err. | ||
*/ | ||
all<A, B, C, D, E1, E2, E3, E4>(a: Result<E1, A>, b: Result<E2, B>, c: Result<E3, C>, d: Result<E4, D>): Result<E1 | E2 | E3 | E4, [A, B, C, D]>; | ||
/** | ||
* Creates a new Ok Result holding the tuple of all the passed values if they were all Ok, | ||
* else returns the first encountered Err. | ||
*/ | ||
all<A, E>(...results: Result<E, A>[]): Result<E, A[]>; | ||
@@ -40,0 +52,0 @@ } |
@@ -1,2 +0,2 @@ | ||
import { ArrayOps, ObjectOps, NumberOps, StringOps, BoolOps, Wrapper } from './lift'; | ||
import { ArrayOps, ObjectOps, NumberOps, StringOps, DateOps, BoolOps, Wrapper } from './lift'; | ||
declare module '../wrapper' { | ||
@@ -23,2 +23,7 @@ interface ArrayOps<A> { | ||
declare module '../wrapper' { | ||
interface DateOps { | ||
transform: typeof transform; | ||
} | ||
} | ||
declare module '../wrapper' { | ||
interface BoolOps { | ||
@@ -28,6 +33,49 @@ transform: typeof transform; | ||
} | ||
/** | ||
* Runs an arbitrary function to transform this wrapper into a Number wrapper | ||
*/ | ||
export declare function transform<A>(this: Wrapper<A>, func: (source: A) => number): NumberOps; | ||
/** | ||
* Runs an arbitrary function to transform this wrapper into a number wrapper | ||
*/ | ||
export declare function transform<A>(this: Wrapper<A>, func: (source: A) => NumberOps): NumberOps; | ||
/** | ||
* Runs an arbitrary function to transform this wrapper into a string wrapper | ||
*/ | ||
export declare function transform<A>(this: Wrapper<A>, func: (source: A) => string): StringOps; | ||
/** | ||
* Runs an arbitrary function to transform this wrapper into a string wrapper | ||
*/ | ||
export declare function transform<A>(this: Wrapper<A>, func: (source: A) => StringOps): StringOps; | ||
/** | ||
* Runs an arbitrary function to transform this wrapper into a boolean wrapper | ||
*/ | ||
export declare function transform<A>(this: Wrapper<A>, func: (source: A) => boolean): BoolOps; | ||
/** | ||
* Runs an arbitrary function to transform this wrapper into a boolean wrapper | ||
*/ | ||
export declare function transform<A>(this: Wrapper<A>, func: (source: A) => BoolOps): BoolOps; | ||
/** | ||
* Runs an arbitrary function to transform this wrapper into a date wrapper | ||
*/ | ||
export declare function transform<A>(this: Wrapper<A>, func: (source: A) => Date): DateOps; | ||
/** | ||
* Runs an arbitrary function to transform this wrapper into a date wrapper | ||
*/ | ||
export declare function transform<A>(this: Wrapper<A>, func: (source: A) => DateOps): DateOps; | ||
/** | ||
* Runs an arbitrary function to transform this wrapper into a array wrapper | ||
*/ | ||
export declare function transform<A, B>(this: Wrapper<A>, func: (source: A) => B[]): ArrayOps<B>; | ||
/** | ||
* Runs an arbitrary function to transform this wrapper into a array wrapper | ||
*/ | ||
export declare function transform<A, B>(this: Wrapper<A>, func: (source: A) => ArrayOps<B>): ArrayOps<B>; | ||
/** | ||
* Runs an arbitrary function to transform this wrapper into an object wrapper | ||
*/ | ||
export declare function transform<A, B>(this: Wrapper<A>, func: (source: A) => B): ObjectOps<B>; | ||
/** | ||
* Runs an arbitrary function to transform this wrapper into an object wrapper | ||
*/ | ||
export declare function transform<A, B>(this: Wrapper<A>, func: (source: A) => ObjectOps<B>): ObjectOps<B>; |
@@ -1,7 +0,4 @@ | ||
import lift, { ArrayOps, ObjectOps, NumberOps, StringOps, BoolOps } from './lift'; | ||
/** | ||
* Runs an arbitrary transformation. | ||
*/ | ||
import lift, { ArrayOps, ObjectOps, NumberOps, StringOps, DateOps, BoolOps, getValue } from './lift'; | ||
export function transform(func) { | ||
return lift(func(this.value())); | ||
return lift(getValue(func(this.value()))); | ||
} | ||
@@ -13,1 +10,2 @@ NumberOps.prototype.transform = transform; | ||
ObjectOps.prototype.transform = transform; | ||
DateOps.prototype.transform = transform; |
{ | ||
"name": "space-lift", | ||
"version": "0.4.3", | ||
"version": "0.4.4", | ||
"description": "Idiomatic TS array, object utils, Option, Result monads", | ||
@@ -5,0 +5,0 @@ |
@@ -111,3 +111,3 @@ **space-lift** | ||
Most of the time, you will have to call `.value()` to read your value back (or `.get()` for options, although it is recommended to use `map`/`getOrElse`/etc instead) | ||
Because it's distracting to write `.value()` more than once per chain, some operators will automatically unwrap values returned from their iterators. | ||
Because it's distracting to write `.value()` more than once per chain, some operators will automatically unwrap values returned from their iterators (like Promise->then). | ||
These operators are: | ||
@@ -119,2 +119,3 @@ | ||
- `Array.updateAt` | ||
- `transform` | ||
@@ -121,0 +122,0 @@ |
@@ -48,2 +48,12 @@ | ||
export interface BoolOps extends Wrapper<boolean> {} | ||
export interface BoolOps extends Wrapper<boolean> {} | ||
export interface DateOpsConstructor { | ||
new(value: Date): DateOps | ||
readonly prototype: DateOps | ||
} | ||
export interface DateOps extends Wrapper<Date> {} | ||
147357
4082
530