Checks if the given value is a Generator Function.

Syntax

TypeScript
import { isGeneratorFunction } from '@opentf/std';

isGeneratorFunction(
  val: unknown
): val is GeneratorFunction

Examples

TypeScript
isGeneratorFunction(function() {}) //=> false

isGeneratorFunction({}) //=> false

function* generator(i) {
  yield i;
  yield i + 10;
}

isGeneratorFunction(generator); //=> true

async function* aGen(i) {
  yield i;
  yield i + 10;
}

isGeneratorFunction(aGen); //=> false

const someObj = {
  *generator() {
    yield "a";
    yield "b";
  },
};

isGeneratorFunction(someObj.generator); //=> true
Last updated on
Edit this page