NAME
FP::Hash
SYNOPSIS
use FP::Hash;
my $a= {a=>1, b=>2};
my $b= hash_set($a, "b", 3);
my $c= hash_delete($b, "a");
if (my ($v)= hash_perhaps_ref ($c, "x")) {
...
}
my $d= hash_update $a, 'a', sub { $_[0]+10 };
# +{ a=> 11, b=> 2 };
my $e= hash_update $a, 'x', sub { [@_] };
# +{ a=> 1, b=> 2, x=>[] };
# The function passed to hash_update is run in list context! Empty
# list means, delete the item.
my $e= hash_update $a, 'a', sub { () };
# +{ b=> 2 };
print Dumper($c); # {b => 3}
print Dumper($a); # {a => 1, b => 2}
subhash({a=>10, b=>11, c=>12}, "a", "c") # {a=>10, c=>12};
DESCRIPTION
Provides pure functions on hash tables. Note though that hash table updates simply copy the whole hash table, thus you may easily get bad computational complexity. (If you really care about that, and not so much about interoperability with other Perl code, perhaps port a functional hash tables implementation (like the one used by Clojure)?)