summaryrefslogtreecommitdiff
path: root/src/prelude/array.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/prelude/array.ts')
-rw-r--r--src/prelude/array.ts8
1 files changed, 8 insertions, 0 deletions
diff --git a/src/prelude/array.ts b/src/prelude/array.ts
index 44482c57cd..839bbc920b 100644
--- a/src/prelude/array.ts
+++ b/src/prelude/array.ts
@@ -120,3 +120,11 @@ export function cumulativeSum(xs: number[]): number[] {
export function fromEntries(xs: [string, any][]): { [x: string]: any; } {
return xs.reduce((obj, [k, v]) => Object.assign(obj, { [k]: v }), {} as { [x: string]: any; });
}
+
+export function toArray<T>(x: T | T[] | undefined): T[] {
+ return Array.isArray(x) ? x : x != null ? [x] : [];
+}
+
+export function toSingle<T>(x: T | T[] | undefined): T | undefined {
+ return Array.isArray(x) ? x[0] : x;
+}