mmm-0.1.0.0: Minecraft 1.21.4 implementation in Haskell
Copyright(c) axionbuster 2025
LicenseBSD-3-Clause
Safe HaskellNone
LanguageGHC2021

M.IO.Obs

Contents

Description

This module provides a general-purpose observer pattern implementation for monitoring and reacting to state changes in STM transactions.

Synopsis
  • obs :: forall (es :: [Effect]) a b. (Concurrent :> es, Eq a) => TVar a -> (a -> a -> STM a) -> (a -> a -> Eff es ()) -> Eff es b

Observer

obs Source #

Arguments

:: forall (es :: [Effect]) a b. (Concurrent :> es, Eq a) 
=> TVar a

Target variable to observe for changes

-> (a -> a -> STM a)

Function to compare and transform old and new values in STM

Old value is passed first; returned value gets committed and remembered

-> (a -> a -> Eff es ())

Action to execute when changes are detected, with old and new values

Old value is passed first

-> Eff es b 

A general observer that monitors changes in a shared variable and reacts to them.

The observer watches a target variable for changes, compares values using a custom comparison function, and executes an action when changes are detected.

obs targetvar              -- Variable to observe
    compareandtransform    -- STM function to compare and transform values
    reacttochange          -- Action to execute when changes occur