Phunkie Guy

Pλunkie

Functional Programming for PHP

Bring the power of functional programming to PHP with Phunkie. Immutable data structures, type-safe operations, lazy evaluation, and a powerful REPL for interactive development.

Phunkie
$ phunkie
Welcome to phunkie console.

Type in expressions to have them evaluated.

phunkie > ImmList(1, 2, 3, 4, 5)
$var0: ImmList<Int> = List(1, 2, 3, 4, 5)
phunkie >

Why Functional Programming in PHP?

Write safer, more maintainable code with functional programming principles

🔒

Immutability

Data structures that never change, eliminating a whole class of bugs and making your code more predictable.

🎯

Type Safety

Strong typing with Option, Either, and Validation types to handle errors gracefully and make invalid states unrepresentable.

Lazy Evaluation

Work with infinite data structures and defer computation until needed, improving performance and expressiveness.

🧩

Composability

Build complex operations from simple, reusable functions using map, flatMap, filter, and other combinators.

📐

Lean Modelling

Express complex domain logic concisely with algebraic data types and pattern matching, reducing boilerplate and cognitive load.

📚

Rich Library

Comprehensive collection of functional data structures, monads, and utilities inspired by Scala and Haskell ecosystems.

Phunkie Console

An interactive REPL for exploring functional programming concepts

Interactive Development

The Phunkie Console provides a powerful REPL (Read-Eval-Print Loop) for interactive development. Experiment with functional programming concepts, test your code, and explore type signatures in real-time.

  • :type - Inspect the type of any expression
  • :kind - Explore higher-kinded types
  • :vars - List all defined variables
  • :load - Import .phunkie files
  • Syntax highlighting for better readability
  • History navigation with arrow keys

Install:

composer require phunkie/console

Run:

./vendor/bin/phunkie
phunkie console
// Welcome to phunkie console.

phunkie > ImmList(1, 2, 3, 4, 5)
$var0: ImmList<Int> = List(1, 2, 3, 4, 5)

phunkie > $var0->map(fn($x) => $x * 2)
$var1: ImmList<Int> = List(2, 4, 6, 8, 10)

phunkie > Some(42)->map(fn($x) => $x + 8)
$var2: Option<Int> = Some(50)

phunkie > :type $var2
Option<Int>

phunkie > :kind Option
* -> *
Learn More →

Phunkie Streams

Lazy, infinite, and composable stream processing

streams.php
use Phunkie\Streams\Stream;

// Create an infinite stream of natural numbers
$naturals = Stream::iterate(1, fn($n) => $n + 1);

// Take first 10 even numbers
$evens = $naturals
    ->filter(fn($n) => $n % 2 === 0)
    ->take(10)
    ->toList();

// Stream from a file lazily
$lines = Stream::fromFile('data.txt')
    ->map(fn($line) => trim($line))
    ->filter(fn($line) => !empty($line));
Learn More →

Lazy Stream Processing

Handle infinite sequences, process large files efficiently, and compose complex transformations with ease. Streams are evaluated lazily, meaning computations are only performed when needed.

  • Work with infinite sequences
  • Memory efficient processing
  • Composable transformations
  • Built-in file I/O support
  • Resource-safe operations

Install:

composer require phunkie/streams

Phunkie Effect

Manage side effects safely with the IO monad

Pure Functional Side Effects

The Effect system allows you to describe side effects as values, making them composable, testable, and referentially transparent. Separate effect description from execution for better reasoning about your code.

  • IO monad for side effects
  • Async operations support
  • Error handling with Either
  • Resource management
  • Concurrent execution
  • Stack-safe recursion

Install:

composer require phunkie/effect
effects.php
use Phunkie\Effect\IO;

// Describe effects as values
$readFile = new IO(fn() =>
    file_get_contents('config.json')
);

$parseJson = fn($content) =>
    new IO(fn() => json_decode($content));

// Compose effects
$program = $readFile
    ->flatMap($parseJson)
    ->map(fn($config) => $config->database)
    ->handleError(fn($e) =>
        defaultConfig()
    );

// Execute effects
$result = $program->unsafeRun();
Learn More →

Documentation

Everything you need to get started with Phunkie

Join the Community

Contribute, ask questions, and help shape the future of functional PHP