francisrstokes / arcsecond

✨Zero Dependency Parser Combinator Library for JS Based on Haskell's Parsec
555 stars 28 forks source link

Refactor coroutine to improve type inference #90

Closed ghost closed 1 year ago

ghost commented 1 year ago

Changed the coroutine function to use regular function instead of generator to Provide Better Type Checking

Coroutine function has been changed to use a regular function instead of generator function. It would provide type intellisense while working with coroutines. New Usage is provide below.

Old Usage:

const p = coroutine(function*() {
      const firstPart = yield letters;
      const secondPart = yield digits;
      return {
        result: [firstPart, secondPart],
      };
    });

New Usage:

const p = coroutine(tokenize => {
      const firstPart = tokenize(letters);
      const secondPart = tokenize(digits);
      return {
        result: [firstPart, secondPart],
      };
    });