-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Add doctest example for OptionT #4777
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
base: main
Are you sure you want to change the base?
Conversation
/** | ||
* OptionT is a wrapper for computations of type F[Option[A]]. | ||
* | ||
* Example: | ||
* {{{ | ||
* import cats.data.OptionT | ||
* import cats.implicits._ | ||
* | ||
* val result = OptionT(List(Option(1), None, Option(3))) | ||
* result.map(_ + 1) | ||
* // res0: cats.data.OptionT[List, Int] = OptionT(List(Some(2), None, Some(4))) | ||
* }}} | ||
*/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's a ScalaDoc for OptionT already right above this one. If the goal is to add an example, then it makes sense to simply add the example section to the above ScalaDoc, rather than creating a whole new ScalaDoc itself.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the feedback! I’ve merged the example into the existing ScalaDoc as suggested.
Please let me know if any further adjustments are needed.
Thanks for your work on this PR! Unfortunately, I think doctests have to be added directly to the documentation for methods. In this case, you added examples to documentation for the I think |
Thank you for the feedback! I understand now that doctests should be added to the method-level documentation rather than the class-level ScalaDoc. I’ll review the existing doctests for OptionT and either update this PR to include method-level examples or open a new PR adding doctests to another datatype that still needs them. |
This PR introduces doctests for the OptionT data type in cats-core. The doctests serve two purposes:
Documentation enhancement – providing clear, usage-based examples for OptionT methods, helping developers understand common patterns and behaviors.
Test coverage improvement: ensuring that examples in the documentation are verified, reducing the likelihood of outdated or incorrect examples.
Changes:
Added doctests for key OptionT methods, including basic construction, mapping, flatMapping, and combinators.
Ensured examples are simple, concise, and runnable as tests.
Benefits:
Improves developer experience by providing verified, practical examples.
Strengthens test suite coverage indirectly by validating examples in documentation.