Skip to content

feat(Predicate): updated doc comments for clarity and examples in the Predicate module #5094

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

doeixd
Copy link

@doeixd doeixd commented Jun 24, 2025

feat(Predicate): updated doc comments for clarity and examples in the Predicate module

The key improvements include:

  • Enhanced Clarity: All doc comments have been rewritten to be more intuitive and accessible. Complex logical combinators like implies now feature real-world analogies (e.g., the "if-then promise") to make them easier to understand.

  • Comprehensive Examples: Added or improved usage examples for nearly every function. These examples focus on demonstrating both the boolean logic and the powerful type-narrowing capabilities of Refinements.

  • Crucial Technical Details: Added important notes for TypeScript developers, such as the logical equivalence of implies to !p || q and an explicit warning that it does not produce a Refinement, preventing common pitfalls.

  • Improved Readability: Standardized the format, added explanatory notes to examples, and ensured a consistent, helpful tone throughout the module's documentation.

This change does not alter any runtime code but makes the module substantially easier to learn, use correctly, and integrate into projects.

Type

  • Refactor
  • Feature
  • Bug Fix
  • Optimization
  • Documentation Update

Description

  • Enhanced Clarity: All doc comments have been rewritten to be more intuitive and accessible. Complex logical combinators like implies now feature real-world analogies (e.g., the "if-then promise") to make them easier to understand.

  • Comprehensive Examples: Added or improved usage examples for nearly every function. These examples focus on demonstrating both the boolean logic and the powerful type-narrowing capabilities of Refinements.

  • Crucial Technical Details: Added important notes for TypeScript developers, such as the logical equivalence of implies to !p || q and an explicit warning that it does not produce a Refinement, preventing common pitfalls.

  • Improved Readability: Standardized the format, added explanatory notes to examples, and ensured a consistent, helpful tone throughout the module's documentation.

This change does not alter any runtime code but makes the module substantially easier to learn, use correctly, and integrate into projects.

Related

  • Related Issue #
  • Closes #

… Predicate module

The key improvements include:

- **Enhanced Clarity:** All doc comments have been rewritten to be more intuitive and accessible. Complex logical combinators like `implies` now feature real-world analogies (e.g., the "if-then promise") to make them easier to understand.

- **Comprehensive Examples:** Added or improved usage examples for nearly every function. These examples focus on demonstrating both the boolean logic and the powerful type-narrowing capabilities of `Refinement`s.

- **Crucial Technical Details:** Added important notes for TypeScript developers, such as the logical equivalence of `implies` to `!p || q` and an explicit warning that it does not produce a `Refinement`, preventing common pitfalls.

- **Improved Readability:** Standardized the format, added explanatory notes to examples, and ensured a consistent, helpful tone throughout the module's documentation.

This change does not alter any runtime code but makes the module substantially easier to learn, use correctly, and integrate into projects.
@doeixd doeixd requested a review from mikearnaldi as a code owner June 24, 2025 14:01
@github-project-automation github-project-automation bot moved this to Discussion Ongoing in PR Backlog Jun 24, 2025
Copy link

changeset-bot bot commented Jun 24, 2025

⚠️ No Changeset found

Latest commit: c2a1ef3

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

The code fences were accidently removed, I added them back
Copy link
Contributor

@gcanti gcanti left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are a few examples that don't type-check. You can check locally by running pnpm docgen in the effect package.

Comment on lines +2 to +15
* This module provides a collection of functions for working with predicates and refinements.
*
* A `Predicate<A>` is a function that takes a value of type `A` and returns a boolean.
* It is used to check if a value satisfies a certain condition.
*
* A `Refinement<A, B>` is a special type of predicate that not only checks a condition
* but also provides a type guard, allowing TypeScript to narrow the type of the input
* value from `A` to a more specific type `B` within a conditional block.
*
* The module includes:
* - Basic predicates and refinements for common types (e.g., `isString`, `isNumber`).
* - Combinators to create new predicates from existing ones (e.g., `and`, `or`, `not`).
* - Advanced combinators for working with data structures (e.g., `tuple`, `struct`).
* - Type-level utilities for inspecting predicate and refinement types.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This must be copied into the index.ts file. You can run pnpm codegen to do it automatically.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, this may be a stupid question, but after I run pnpm docgen, where can I check the typescript issues?

PS C:\Users\Patrick\effect\packages\effect> pnpm docgen
[14:01:44.792] INFO (#12): Reading modules...
[14:01:44.903] INFO (#12): 173 module(s) found
[14:01:44.990] INFO (#12): Parsing modules...
[14:01:59.759] INFO (#12): Checking modules...
[14:01:59.852] INFO (#12): No examples found.
[14:01:59.861] INFO (#12): Creating markdown files...
[14:02:23.687] INFO (#12): Writing markdown files...
[14:02:24.468] INFO (#12): Docs generation succeeded!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

after I run pnpm docgen, where can I check the typescript issues?

docs/examples folder, see https://github.com/Effect-TS/effect/actions/runs/15852817946/job/44692764087?pr=5094

@@ -226,16 +334,20 @@ export const isMap = (input: unknown): input is Map<unknown, unknown> => input i
export const isString = (input: unknown): input is string => typeof input === "string"

/**
* Tests if a value is a `number`.
* A refinement that checks if a value is a `number`. Note that this
* check returns `false` for `NaN`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AFAIK this is not true

import { Predicate } from "effect"

console.log(Predicate.isNumber(NaN))
// true

@github-project-automation github-project-automation bot moved this from Discussion Ongoing to Waiting on Author in PR Backlog Jun 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Waiting on Author
Development

Successfully merging this pull request may close these issues.

2 participants