Skip to content

Add simple use-effect-like behavior simulation in Python#14512

Open
kadambari25 wants to merge 1 commit intoTheAlgorithms:masterfrom
kadambari25:use-effect-example
Open

Add simple use-effect-like behavior simulation in Python#14512
kadambari25 wants to merge 1 commit intoTheAlgorithms:masterfrom
kadambari25:use-effect-example

Conversation

@kadambari25
Copy link
Copy Markdown

Describe your change:

  • Add an algorithm?
  • Fix a bug or typo in an existing algorithm?
  • Add or change doctests?
  • Documentation change?

This PR adds a simple Python implementation that simulates "useEffect"-like behavior by executing a callback when a dependency changes.

The original issue lacked sufficient context and did not clearly describe a specific bug or feature. To address this, I implemented a small educational example that demonstrates a similar concept in Python.

The implementation includes:

  • A function to simulate dependency-based execution
  • Type hints for clarity
  • Doctests to ensure correctness
  • Documentation explaining the concept

Reference:
https://un5qgjbzw9dxcq3ecfxberhh.julianrbryant.com/wiki/Reactive_programming

Checklist:

  • I have read CONTRIBUTING.md.
  • This pull request is all my own work -- I have not plagiarized.
  • I know that pull requests will not be merged if they fail the automated tests.
  • This PR only changes one algorithm file.
  • All new Python files are placed inside an existing directory.
  • All filenames are in all lowercase characters with no spaces or dashes.
  • All functions and variable names follow Python naming conventions.
  • All function parameters and return values are annotated with Python type hints.
  • All functions have doctests that pass the automated testing.
  • All new algorithms include at least one URL that points to Wikipedia or another similar explanation.
  • Fixes use effect #14299

@algorithms-keeper algorithms-keeper bot added awaiting reviews This PR is ready to be reviewed tests are failing Do not merge until tests pass labels Apr 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting reviews This PR is ready to be reviewed tests are failing Do not merge until tests pass

Projects

None yet

Development

Successfully merging this pull request may close these issues.

use effect

2 participants