flow2schema/src/utils.js

22 lines
437 B
JavaScript
Raw Normal View History

2017-11-18 12:38:34 +03:00
import * as assert from 'assert';
2017-11-21 15:28:59 +03:00
// I so much dream about the user guards...
// @see flow#112.
export const invariant = assert.ok;
2017-11-28 17:42:19 +03:00
export function last<T>(list: T[]): T {
invariant(list.length > 0);
return list[list.length - 1];
2017-11-21 15:28:59 +03:00
}
2017-12-16 17:03:08 +03:00
export function collect<T>(iter: Iterable<[string, T]>): {[string]: T} {
const result = {};
for (const [key, value] of iter) {
result[key] = value;
}
return result;
}