提交 a340b1ae 编写于 作者: J Joao Moreno

arrays.insert

上级 ee707fc3
......@@ -265,4 +265,19 @@ export function index<T,R>(array: T[], indexer: (t: T) => string, merger: (t: T,
r[key] = merger(t, r[key]);
return r;
}, Object.create(null));
}
/**
* Inserts an element into an array. Returns a function which, when
* called, will remove that element from the array.
*/
export function insert<T>(array: T[], element: T): () => void {
array.push(element);
return () => {
const index = array.indexOf(element);
if (index > -1) {
array.splice(index, 1);
}
};
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册