++ed by:
JGAMBLE RPAVLOV

2 PAUSE users
1 non-PAUSE user.

Christian Jaeger
and 1 contributors

NAME

FP::Hash

SYNOPSIS

 use FP::Equal 'is_equal';
 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")) {
    is_equal $v, "XXX";
 }
 is_equal hash_update($a, 'a', sub { $_[0]+10 }),
          +{ a=> 11, b=> 2 };
 is_equal 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 { () };
 is_equal $e, +{ b=> 2 };

 is_equal $c, +{b => 3};
 is_equal $a, +{a => 1, b => 2};

 is_equal 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)?)