function toFunction(obj) {
  let styleFunction;

  if (typeof obj === 'function') {
    styleFunction = obj;
  } else {
    /**
     * @type {Array<Style>}
     */
    let styles;
    if (Array.isArray(obj)) {
      styles = obj;
    } else {
      assert(
        typeof (/** @type {?} */ (obj).getZIndex) === 'function',
        'Expected an `Style` or an array of `Style`',
      );
      const style = /** @type {Style} */ (obj);
      styles = [style];
    }
    styleFunction = function () {
      return styles;
    };
  }
  return styleFunction;
}
Convert the provided object into a style function.  Functions passed through
unchanged.  Arrays of Style or single style objects wrapped in a
new style function.
@param {StyleFunction|Array<Style>|Style} obj
    A style function, a single style, or an array of styles.
@return {StyleFunction} A style function.