semvec/pypi-packages huggingface dataset:
posted 0.1.5
Interfacing with message-broker functionality
License: mit


# posted
Interfacing with message-broker functionality


To install:	```pip install posted```


# Examples

## ReactiveScope

A scope that reacts to writes by computing associated functions, themselves writing in the scope, creating a chain reaction that propagates information through the scope.

Parameters
----------

* `func_nodes : Iterable[ReactiveFuncNode]`
    The functions that will be called when the scope is written to.
* `scope_factory : Callable[[], MutableMapping]`
    A factory that returns a new scope. The scope will be cleared by calling this
    factory at each call to `.clear()`.

Examples
--------

First, we need some func nodes to define the reaction relationships.
We'll stuff these func nodes in a DAG, for ease of use, but it's not necessary.

```python
>>> from meshed import FuncNode, DAG
>>>
>>> def f(a, b):
...     return a + b
>>> def g(a_plus_b, d):
...     return a_plus_b * d
>>> f_node = FuncNode(func=f, out='a_plus_b')
>>> g_node = FuncNode(func=g, bind={'d': 'b'})
>>> d = DAG((f_node, g_node))
>>>
>>> print(d.dot_digraph_ascii())
<BLANKLINE>
                a
<BLANKLINE>
            │
            │
            ▼
            ┌────────┐
    b   ──▶ │   f    │
            └────────┘
    │         │
    │         │
    │         ▼
    │
    │        a_plus_b
    │
    │         │
    │         │
    │         ▼
    │       ┌────────┐
    └─────▶ │   g_   │
            └────────┘
            │
            │
            ▼
<BLANKLINE>
                g
<BLANKLINE>
```

Now we make a scope with these func nodes.

```python
>>> s = ReactiveScope(d)
```

The scope starts empty (by default).

```python
>>> s
<ReactiveScope with .scope: {}>
```

So if we try to access any key, we'll get a KeyError.

```python
>>> s['g']  # doctest: +IGNORE_EXCEPTION_DETAIL
Traceback (most recent call last):
    ...
KeyError: 'g'
```

That's because we didn't put write anything in the scope yet.

But, if you give ``g_`` enough data to be able to compute ``g`` (namely, if you
write values of ``b`` and ``a_plus_b``), then ``g`` will automatically be computed.

```python
>>> s['b'] = 3
>>> s['a_plus_b'] = 5
>>> s
<ReactiveScope with .scope: {'b': 3, 'a_plus_b': 5, 'g': 15}>
```

So now we can access ``g``.

```python
>>> s['g']
15
```

Note though, that we first showed that ``g`` appeared in the scope before we
explicitly asked for it. This was to show that ``g`` was computed as a
side-effect of writing to the scope, not because we asked for it, triggering the
computation

Let's clear the scope and show that by specifying ``a`` and ``b``, we get all the
other values of the network.

```python
>>> s.clear()
>>> s
<ReactiveScope with .scope: {}>
>>> s['a'] = 3
>>> s['b'] = 4
>>> s
<ReactiveScope with .scope: {'a': 3, 'b': 4, 'a_plus_b': 7, 'g': 28}>
>>> s['g']  # (3 + 4) * 4 == 7 * 4 == 28
28
```
vd 0.0.11
Value Dispatch: Wire Python functions to stores for seamless input/output handling.
License: mit

# vd

Value Dispatch: Wire Python functions to stores for seamless input/output handling.

To install:	```pip install vd```


# Value Dispatch: An Overview

Value dispatch is a programming concept where values are analyzed and routed to appropriate handlers or functions based on their content, type, or the context in which they are received. This mechanism enables dynamic and flexible handling of inputs, making it particularly useful in scenarios where the action to be taken depends on runtime data.

## Applications of Value Dispatch

Value dispatch is widely applicable across various programming domains, including:

**Command-Line Interfaces (CLIs)**: In a CLI tool, value dispatch can parse and interpret command-line arguments, directing them to the correct subcommands or functions. For instance, a tool might use the first argument to decide whether to add, remove, or list items, streamlining user interactions.

**Web Services**: For web applications, value dispatch routes incoming requests to the appropriate endpoints or controllers based on URL patterns, HTTP methods, or request parameters. This ensures efficient handling of diverse client requests.

**Event-Driven Architectures**: In systems that respond to events, value dispatch directs different event types to specific handlers, ensuring each event is processed appropriately based on its nature.

**Data Processing**: In data pipelines, value dispatch applies different processing logic depending on the characteristics of the input data, enabling customized transformations or analyses.


## Benefits of Value Dispatch

This approach enhances software design by offering:

**Flexibility**: New input types or actions can be integrated easily by adding new dispatch rules, avoiding the need to overhaul existing code.

**Clarity**: By mapping specific values to specific handlers, concerns are separated clearly, improving code readability and maintainability.

**Scalability**: Systems can expand their capabilities without complicating the core logic, supporting long-term growth and adaptation.


## Illustrative Example

Consider a simple CLI tool for managing a library:

`library add <book>`: Adds a book to the library.
`library remove <book>`: Removes a book.
`library list`: Lists all books.

Here, the first argument ("add", "remove", "list") determines which function is executed,
showcasing value dispatch in practice. Similarly, in a web service, 
URLs like `/users/123` or `/books/456` might trigger functions to retrieve specific 
user or book details, respectively.
Value dispatch thus provides a powerful way to organize and execute code based on 
input values, enhancing the responsiveness and maintainability of software systems 
across diverse applications.