export function collectivize(state: S | (() => S)) { return function(collector: (state: S) => D): (() => D) { return () => { const s = typeof state === "function" ? (state as any)() : state return collector(s) } } }