Skip to content

Instantly share code, notes, and snippets.

@dana-ross
Created January 30, 2016 17:49
Show Gist options
  • Save dana-ross/84efc256f612d95b340a to your computer and use it in GitHub Desktop.
Save dana-ross/84efc256f612d95b340a to your computer and use it in GitHub Desktop.
<?php
use DaveRoss\FunctionalProgrammingUtils\Maybe as Maybe;
$good = Maybe::of( json_decode( '{ "label": "This is valid JSON", "value": 5 }' ) );
$bad = Maybe::of( json_decode( '{ "label": This is invalid JSON, "value": 5 }' ) );
$good->map( function( $obj ) { echo $obj->value . "\n"; } );
$bad->map( function( $obj ) { echo $obj->value . "\n"; } );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment