The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

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

NOTE

This is alpha software! Read the status section in the package README or on the website.