@ephox/katamari
Advanced tools
Comparing version 2.4.4 to 2.4.5
import { Option } from './Option'; | ||
/** cat :: [Option a] -> [a] */ | ||
export declare const cat: <A>(arr: Option<A>[]) => A[]; | ||
declare const cat: <A>(arr: Option<A>[]) => A[]; | ||
/** findMap :: ([a], (a, Int -> Option b)) -> Option b */ | ||
export declare const findMap: <A, B>(arr: A[], f: (a: A, index: number) => Option<B>) => Option<B>; | ||
declare const findMap: <A, B>(arr: A[], f: (a: A, index: number) => Option<B>) => Option<B>; | ||
/** | ||
@@ -10,2 +10,7 @@ * if all elements in arr are 'some', their inner values are passed as arguments to f | ||
*/ | ||
export declare const liftN: <B>(arr: Option<any>[], f: (...args: any[]) => B) => Option<B>; | ||
declare const liftN: <B>(arr: Option<any>[], f: (...args: any[]) => B) => Option<B>; | ||
declare function lift<A, B, C>(a: Option<A>, b: Option<B>, f: (a: A, b: B) => C): Option<C>; | ||
declare function lift<A, B, C, D>(a: Option<A>, b: Option<B>, c: Option<C>, f: (a: A, b: B, c: C) => D): Option<D>; | ||
declare function lift<A, B, C, D, E>(a: Option<A>, b: Option<B>, c: Option<C>, d: Option<D>, f: (a: A, b: B, c: C, d: D) => E): Option<E>; | ||
declare function lift<A, B, C, D, E, F>(a: Option<A>, b: Option<B>, c: Option<C>, d: Option<D>, e: Option<E>, f: (a: A, b: B, c: C, d: D, e: E) => F): Option<F>; | ||
export { cat, findMap, liftN, lift }; |
import { Option } from './Option'; | ||
/** cat :: [Option a] -> [a] */ | ||
export var cat = function (arr) { | ||
var cat = function (arr) { | ||
var r = []; | ||
@@ -14,3 +14,3 @@ var push = function (x) { | ||
/** findMap :: ([a], (a, Int -> Option b)) -> Option b */ | ||
export var findMap = function (arr, f) { | ||
var findMap = function (arr, f) { | ||
for (var i = 0; i < arr.length; i++) { | ||
@@ -28,3 +28,3 @@ var r = f(arr[i], i); | ||
*/ | ||
export var liftN = function (arr, f) { | ||
var liftN = function (arr, f) { | ||
var r = []; | ||
@@ -42,2 +42,12 @@ for (var i = 0; i < arr.length; i++) { | ||
}; | ||
function lift() { | ||
var args = []; | ||
for (var _i = 0; _i < arguments.length; _i++) { | ||
args[_i] = arguments[_i]; | ||
} | ||
var f = args.pop(); | ||
return liftN(args, f); | ||
} | ||
; | ||
export { cat, findMap, liftN, lift }; | ||
//# sourceMappingURL=Options.js.map |
@@ -74,3 +74,13 @@ import * as Arr from 'ephox/katamari/api/Arr'; | ||
}); | ||
Jsc.property('Options.lift with two arguments mirrors cat with two items', ArbDataTypes.option, ArbDataTypes.option, Jsc.fun(Jsc.json), function (a, b, f) { | ||
var args = Options.cat([a, b]); | ||
var output = Options.lift(a, b, f); | ||
if (args.length === 2) { | ||
return Jsc.eq(output.getOrDie(), f.apply(undefined, args)); | ||
} | ||
else { | ||
return output.isNone(); | ||
} | ||
}); | ||
}); | ||
//# sourceMappingURL=OptionsTest.js.map |
{ | ||
"name": "@ephox/katamari", | ||
"version": "2.4.4", | ||
"version": "2.4.5", | ||
"description": "Basic data type library", | ||
@@ -5,0 +5,0 @@ "repository": { |
import { Option } from './Option'; | ||
/** cat :: [Option a] -> [a] */ | ||
export const cat = function <A> (arr: Option<A>[]) { | ||
const cat = function <A> (arr: Option<A>[]) { | ||
const r: A[] = []; | ||
@@ -16,3 +16,3 @@ const push = function (x: A) { | ||
/** findMap :: ([a], (a, Int -> Option b)) -> Option b */ | ||
export const findMap = function <A, B> (arr: A[], f: (a: A, index: number) => Option<B>) { | ||
const findMap = function <A, B> (arr: A[], f: (a: A, index: number) => Option<B>) { | ||
for (let i = 0; i < arr.length; i++) { | ||
@@ -31,3 +31,3 @@ const r = f(arr[i], i); | ||
*/ | ||
export const liftN = function <B> (arr: Option<any>[], f: (...args: any[]) => B) { | ||
const liftN = function <B> (arr: Option<any>[], f: (...args: any[]) => B) { | ||
const r: any[] = []; | ||
@@ -43,2 +43,18 @@ for (let i = 0; i < arr.length; i++) { | ||
return Option.some(<B>f.apply(null, r)); | ||
}; | ||
}; | ||
function lift<A, B, C>(a: Option<A>, b: Option<B>, f: (a: A, b: B) => C): Option<C>; | ||
function lift<A, B, C, D>(a: Option<A>, b: Option<B>, c: Option<C>, f: (a: A, b: B, c: C) => D): Option<D>; | ||
function lift<A, B, C, D, E>(a: Option<A>, b: Option<B>, c: Option<C>, d: Option<D>, f: (a: A, b: B, c: C, d: D) => E): Option<E>; | ||
function lift<A, B, C, D, E, F>(a: Option<A>, b: Option<B>, c: Option<C>, d: Option<D>, e: Option<E>, f: (a: A, b: B, c: C, d: D, e: E) => F): Option<F>; | ||
function lift(...args) { | ||
const f = args.pop(); | ||
return liftN(args, f); | ||
}; | ||
export { | ||
cat, | ||
findMap, | ||
liftN, | ||
lift | ||
}; |
@@ -145,3 +145,20 @@ import * as Arr from 'ephox/katamari/api/Arr'; | ||
); | ||
Jsc.property( | ||
'Options.lift with two arguments mirrors cat with two items', | ||
ArbDataTypes.option, | ||
ArbDataTypes.option, | ||
Jsc.fun(Jsc.json), | ||
function (a, b, f) { | ||
const args = Options.cat([a, b]); | ||
const output = Options.lift(a, b, f); | ||
if (args.length === 2) { | ||
return Jsc.eq(output.getOrDie(), f.apply(undefined, args)); | ||
} else { | ||
return output.isNone(); | ||
} | ||
} | ||
); | ||
}); | ||
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
804343
13375