Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Doctest are not actually tested. Only type-checked. #47

Closed
pixeleet opened this issue Mar 20, 2022 · 4 comments
Closed

Doctest are not actually tested. Only type-checked. #47

pixeleet opened this issue Mar 20, 2022 · 4 comments
Assignees
Labels
documentation Improvements or additions to documentation enhancement New feature or request

Comments

@pixeleet
Copy link
Collaborator

I assume wrong and the examples we provide are not actually running when we call deno test --doc
Therefore the following typechecks but is wrong:

/**
 * Fold away the inner Either from the `TaskEither` leaving us with the
 * result of our computation in the form of a `Task`
 *
 * ```ts
 * import { assertEquals } from "https://deno.land/std/testing/asserts.ts";
 * import * as TE from "./task_either.ts";
 * import * as E from "./either.ts";
 * import * as T from "./task.ts";
 * import { flow, identity } from "./fns.ts";
 *
 * const hello = flow(
 *  TE.fold(() => 'World', identity),
 *  T.map(name => `Hello ${name}!`),
 * );
 *
 * assertEquals(await hello(TE.right('Functional!'))(), E.right("Hello Functional!!"));
 * assertEquals(await hello(TE.left(Error))(), E.right("Hello World!"));
 * ```
 */
export function fold<L, R, B>(
  onLeft: (left: L) => B,
  onRight: (right: R) => B,
): (ta: TaskEither<L, R>) => Task<B> {
  return (ta) => () => ta().then(eitherFold<L, R, B>(onLeft, onRight));
}

Whereas the actually valid example code is:

/**
 * Fold away the inner Either from the `TaskEither` leaving us with the
 * result of our computation in the form of a `Task`
 *
 * ```ts
 * import { assertEquals } from "https://deno.land/std/testing/asserts.ts";
 * import * as TE from "./task_either.ts";
 * import * as T from "./task.ts";
 * import { flow, identity } from "./fns.ts";
 * 
 * const hello = flow(
 *   TE.fold(() => "World", identity),
 *   T.map((name) => `Hello ${name}!`),
 * );
 * 
 * assertEquals(await hello(TE.right("Functional!"))(), "Hello Functional!!");
 * assertEquals(await hello(TE.left(Error))(), "Hello World!");
 * ```
 */
export function fold<L, R, B>(
  onLeft: (left: L) => B,
  onRight: (right: R) => B,
): (ta: TaskEither<L, R>) => Task<B> {
  return (ta) => () => ta().then(eitherFold<L, R, B>(onLeft, onRight));
}
@baetheus
Copy link
Owner

Type checking is good enough, I think. Ultimately, test coverage should all be under ./testing anyway. It's just helpful to know our examples are borked at the type level.

@pixeleet
Copy link
Collaborator Author

I feel bad about having submitted a non working example. We should not be able to provide examples to consumers of the library that don't actually work.

Haven't validated the idea yet, just from the top of my head, it would be interesting to look at what happens internally when we run deno test --doc maybe we could submit a PR on the deno side to add an --exec flag that also tries to execute the example code?

@baetheus
Copy link
Owner

Looks like there is some movement on this in denoland/deno#4716.

@pixeleet pixeleet added documentation Improvements or additions to documentation enhancement New feature or request labels Mar 20, 2022
@pixeleet pixeleet self-assigned this Apr 1, 2022
@baetheus
Copy link
Owner

baetheus commented Jul 5, 2023

Closing this since it's an enhancement in deno.

@baetheus baetheus closed this as completed Jul 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants