Bubble Foundry


BFCollections

by Peter.

I’ve been doing a bunch of PHP programming the last few weeks for a client and it’s been such a pain to use PHP’s archaic array_* methods. And don’t get me started on having to return arrays like array('result' => 'not_ok', 'message' => 'User not found') to indicate success or failure. I had some time to kill at the airport yesterday, so today I am happy to bring you BFCollections. The collections included are:

  • BFArray: A better array. It can be used just like a native array but it also has methods for common array operations such as map, filter, and reduceLeft.
  • Option: Indicates an optional return result, via the form of an instance of the Some class or the global $None. Inspired by Scala’s Option (naturally) and Haskell’s Maybe. There are basic methods to operate on the values.
  • Box: Again indicates an optional return result, though the lack of a value can also be indicated and even chained. Inspired by the Lift framework’s Box.

If there’s interest I’ll see about improving them and even adding additional collections.