# `Patterns.Utils`
[🔗](https://github.com/minnasoft/patterns/blob/v0.0.1/lib/patterns/utils.ex#L1)

Utilities for building pattern modules.

# `ctx`

```elixir
@spec ctx(term()) :: term()
```

Returns a value from the current scoped context.

See `with_ctx/2` for more information.

## Example

    ctx(:binding)
    #=> nil

    with_ctx binding: :references do
      ctx(:binding)
      #=> :references
    end

    ctx(:binding)
    #=> nil

# `defdelegate_all`
*macro* 

Defines delegates for every public function exported by `module`.

## Example

    defmodule MyDelegates do
      import Patterns.Utils

      defdelegate_all String
    end

    MyDelegates.upcase("hello")

Private functions are ignored because only public functions are returned by
`module.__info__(:functions)`.

# `with_ctx`
*macro* 

Runs `block` with scoped process-local context.

`ctx` may be a map or keyword list. It is converted to a map and merged into
the current context for the duration of the block. Nested calls override
duplicate keys while preserving sibling keys.

> #### Process-local context {: .info}
>
> Context is stored in the process dictionary. It is visible only to the current
> process and does not cross `Task`, spawned process, Dataloader, or other async
> boundaries.

The previous context is restored after the block exits, including when the
block raises, throws, or exits.

## Example

    ctx(:binding)
    #=> nil

    with_ctx binding: :references do
      ctx(:binding)
      #=> :references
    end

    ctx(:binding)
    #=> nil

---

*Consult [api-reference.md](api-reference.md) for complete listing*
