Functional programming

Announcing "Thinking Functionally in PHP"

Calling all PHP developers! Want to wrap your brain around functional programming? Are you sick of reading tutorials about this magic "monad" thing but having no idea how to read Haskell? Then this book is for you.

Announcing Thinking Functionally in PHP, by yours truly, available now on LeanPub.

Continue reading this post on PeakD

Larry 20 May 2020 - 9:16am
Type Matching in PHP

One of the nice features of Rust is the match keyword. match is similar to `switch`, but with two key differences:

  1. It requires an exhaustive match, that is, every possible value must be accounted for or a default must be provided.
  2. match is an expression, meaning you can assign the return value of one of its branches to a variable.

That makes match extremely useful for ensuring you handle all possibilities of an enumerated type, say, if using an Optional or Either for error handling. Which... is something I've been experimenting with in PHP.

It's hard to make a PHP equivalent of match that forces an exhaustive match, as PHP lacks enumerated types. However, emulating an expression match turns out to be pretty easy in PHP 7.4, and kind of pretty, too.

Larry 2 February 2020 - 1:46pm

The Functional PHP tour

Submitted by Larry on 13 April 2014 - 11:35pm

Ever heard of functional programming? Not procedural programming, but actual functional programming. Probably, as some fancy academic thing that no one really uses, right?

Did you know you can do it in PHP, too? It's true. In fact, I'll be speaking about it four times in the next couple of weeks!