coderofsalvation/microfunctional

Bare minimum functional programming helpers

dev-master 2020-05-28 19:17 UTC

This package is not auto-updated.

Last update: 2024-12-13 19:28:30 UTC


README

Bare minimum functional programming helpers:

  • curry
  • compose
  • filter
  • fold
  • either

see this video

Usage

$ composer require coderofsalvation/microfunctional

and then

	<?php
		
		/*
		 * simple datastore example
		 */
		$createDefaultItem = function($key){
		  return (object)array("title" => $key);
		};
		$set = function($store,$key,$value){
		  $store->$key = $value;
		};
		$get = function($store,$key){
		  return isset($store->$key) ? $store->$key : false;
		};
		/*
		 * highorder functions using curry 
		 */
		$store        = (object)array();
		$getFromStore = curry( $get,$store);
		$saveToStore  = curry( $set,$store);
		$saveToStore("foo","bar");
		print_r( $getFromStore("foo") );
	?>

License

BSD