Skip to content

✨ Improve unwrap methods#69

Merged
myugen merged 5 commits intobetafrom
feat/improve-matching
May 11, 2025
Merged

✨ Improve unwrap methods#69
myugen merged 5 commits intobetafrom
feat/improve-matching

Conversation

@myugen
Copy link
Collaborator

@myugen myugen commented May 11, 2025

What type of PR is this? (check all applicable)

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

Description

This pull request introduces significant changes to the Either, Option, and Try monads, focusing on replacing the match method with a new fold method for handling both sides of these monads. It also updates the documentation and tests to reflect this change. Additionally, it introduces a new Foldable interface and refactors the Either class to implement it. Below are the most important changes grouped by theme:

API Changes to Monads

  • Replaced the match method with a fold method across Either, Option, and Try monads, providing a more structured and consistent API for handling both sides of these monads. [1] [2] [3] [4] [5] [6]

Documentation Updates

  • Updated the README.md to replace all instances of match with fold, including examples and descriptions for Either, Option, and Try monads. [1] [2] [3] [4]

Added/updated tests?

We encourage you to keep the quality of the code by creating test.

  • Yes
  • No, and this is why: please replace this line with details on why tests
    have not been included
  • I need help with writing tests

@myugen myugen requested a review from Copilot May 11, 2025 20:14
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR improves the unwrapping methods for the monads by replacing the old match method with a new fold method and introducing a Foldable interface. Key changes include:

  • Replacing match with fold in the Try, Option, and Either monads.
  • Updating docs and tests to align with the new fold API.
  • Removing the Matchable interface and its related tests, and adding the Foldable module.

Reviewed Changes

Copilot reviewed 13 out of 13 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/try/try.ts Replaced match method with fold and updated type definitions to implement Foldable.
src/try/try.test.ts Updated tests to call fold instead of match.
src/option/option.ts Replaced match calls with fold calls and updated the interface accordingly.
src/option/option.test.ts Updated tests to use fold for Option instances.
src/match/* Removed Matchable interface and its tests.
src/fold/* Introduced new Foldable interface and its tests.
src/either/either.ts Updated Either to use fold and removed match references.
src/either/either.test.ts Updated tests to use fold for Either instances.
README.md Updated documentation examples to use fold instead of match.
Comments suppressed due to low confidence (1)

README.md:112

  • There is an extraneous 'm' at the end of the import statement. Please remove the stray character.
import { Either } from '@leanmind/monads';m

@myugen myugen requested a review from Copilot May 11, 2025 20:16
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR introduces new fold methods in place of the match methods in the Either, Option, and Try monads to provide a more consistent API for unwrapping values. Key changes include replacing former Matchable interfaces with Foldable, updating associated tests, and revising documentation examples.

Reviewed Changes

Copilot reviewed 13 out of 13 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/try/try.ts Updated Try monad class and its Success/Failure implementations with fold.
src/option/option.ts Updated Option monad class with fold functionality and revised examples.
src/either/either.ts Replaced match methods with fold in Either and revised related API usage.
README.md Updated documentation to reflect the new fold methods and API changes.
Test files (try.test, option.test, either.test, foldable.test) Revised test cases to use fold instead of match.
Removed files in src/match Eliminated remaining Matchable references in favor of Foldable.
Comments suppressed due to low confidence (1)

README.md:112

  • Stray 'm' character found after the import statement; please remove it to clean up the example code.
import { Either } from '@leanmind/monads';m

myugen and others added 2 commits May 11, 2025 21:21
BREAKING CHANGE: The Matchable object has been removed.
Unwrap must be done using new fold API.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@myugen myugen force-pushed the feat/improve-matching branch from 7958093 to 2697226 Compare May 11, 2025 20:22
@myugen myugen requested a review from Copilot May 11, 2025 20:23
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR introduces a new fold method to replace match in the Either, Option, and Try monads, refactoring monad APIs for a more consistent handling of both sides. It updates the monad implementations, test cases, and documentation accordingly.

  • Replaces the match method with fold in Try, Option, and Either.
  • Updates test cases and README examples to reflect the new fold API.
  • Removes the deprecated Matchable interface and adds a new Foldable interface.

Reviewed Changes

Copilot reviewed 13 out of 13 changed files in this pull request and generated no comments.

Show a summary per file
File Description
src/try/try.ts Replaces match with fold and updates the static conversion method.
src/try/try.test.ts Adjusts tests to use fold instead of match.
src/option/option.ts Replaces match with fold and updates the static conversion method.
src/option/option.test.ts Adjusts tests to verify fold behavior for Option.
src/match/* Removes the Matchable interface and related test files.
src/fold/* Introduces the Foldable interface and related types and tests.
src/either/either.ts Replaces match with fold and updates the static conversion method.
src/either/either.test.ts Adjusts tests to use fold instead of match for Either.
README.md Updates documentation and examples to reflect the new fold API.
Comments suppressed due to low confidence (3)

README.md:112

  • The import statement contains a trailing 'm', which should be removed to avoid syntax errors.
import { Either } from '@leanmind/monads';m

README.md:293

  • There is an extra 'm' at the end of the import statement; please remove it.
import { Option } from '@leanmind/monads';m

README.md:413

  • The import statement for Try has an unwanted trailing 'm'; it should be corrected.
import { Try } from '@leanmind/monads';m

@myugen myugen merged commit 8ead9e7 into beta May 11, 2025
3 checks passed
@myugen myugen deleted the feat/improve-matching branch May 11, 2025 20:25
@github-actions
Copy link

🎉 This PR is included in version 2.0.0-beta.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants