# Functional Patterns (`fp`)

Laravel Pipeline-inspired functional utilities for composition and lazy evaluation.

## Features

- **Composition**: `pipe`, `compose`, `apply`
- **Side effects**: `tap`
- **Lazy evaluation**: `Lazy<T>`
- **Memoization**: `memoize`
- **Retry logic**: `retry`
- **Defaults**: `or_default`

## Quick Start

```rust
use rok_utils::fp::{pipe, compose, tap};

// Pipe - thread value through functions
let result = pipe(5, vec![|x| x + 1, |x| x * 2]);
// (5 + 1) * 2 = 12

// Compose - create new functions
let add_then_double = compose(|x: i32| x * 2, |x: i32| x + 1);
assert_eq!(add_then_double(5), 12); // (5 + 1) * 2
```

## Tap (Side Effects)

```rust
use rok_utils::fp::tap;

let mut log = Vec::new();
let result = tap(42, |v| log.push(*v));
assert_eq!(result, 42);
assert_eq!(log, vec![42]);
```

## Lazy Initialization

```rust
use rok_utils::fp::Lazy;

let config = Lazy::new(|| {
    println!("Initializing...");
    "config_value".to_string()
});

println!("Before access");
let value = config.get(); // Only now initializes
```

## Memoization

```rust
use rok_utils::fp::memoize;

let expensive = memoize(|x: i32| {
    println!("Computing...");
    x * x
});

expensive(5); // Computes
expensive(5); // Uses cached result
expensive(3); // Computes new value
```

## Retry Logic

```rust
use rok_utils::fp::retry;

let result = retry(3, || {
    if /* condition */ {
        Ok("success")
    } else {
        Err("failed")
    }
});
```

## Feature Flags

| Feature | Description |
|---------|-------------|
| `full` | Enable all features |
| `random` | Enable `shuffle` function |

## See Also

- [Main examples](../docs/examples.md)
