Skip to content

Conversation

QueenJcloud
Copy link

@QueenJcloud QueenJcloud commented Oct 10, 2025

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.

Comment on lines 33 to 45
/**
* 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)))
* }}}
*/
Copy link
Contributor

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.

Copy link
Author

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.

@armanbilge
Copy link
Member

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 OptionT class itself (not its individual methods). As far as I can tell, these have not been rendered as doctests, since I do not see the new tests appearing in the CI log.

I think OptionT already has doctests for most (all?) of its methods, but there are plenty of other datatypes in Cats that still need doctests.

@QueenJcloud
Copy link
Author

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 OptionT class itself (not its individual methods). As far as I can tell, these have not been rendered as doctests, since I do not see the new tests appearing in the CI log.

I think OptionT already has doctests for most (all?) of its methods, but there are plenty of other datatypes in Cats that still need doctests.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants