diff --git a/README.rst b/README.rst
index ccbd38a..2fb4135 100644
--- a/README.rst
+++ b/README.rst
@@ -444,6 +444,8 @@ treated as matchers. If the matcher returns True for a specific key it is consid
     pvector([1, 2, 4, 4, 5])
     >>> v1.transform([lambda ix: 0 < ix < 4], 8)
     pvector([1, 8, 8, 8, 5])
+    >>> v1.transform([lambda ix, v: ix == 0 or v == 5], 0)
+    pvector([0, 2, 3, 4, 0])
 
     # The (a)ny matcher can be used to match anything
     >>> v1.transform([ny], 8)
diff --git a/pyrsistent/_transformations.py b/pyrsistent/_transformations.py
index c4c7e10..6fe31cf 100644
--- a/pyrsistent/_transformations.py
+++ b/pyrsistent/_transformations.py
@@ -1,5 +1,13 @@
 import re
 import six
+try:
+    from inspect import Parameter, signature
+except ImportError:
+    signature = None
+    try:
+        from inspect import getfullargspec as getargspec
+    except ImportError:
+        from inspect import getargspec
 
 
 def inc(x):
@@ -74,11 +82,40 @@ def _get(structure, key, default):
 def _get_keys_and_values(structure, key_spec):
     from pyrsistent._pmap import pmap
     if callable(key_spec):
-        return [(k, v) for k, v in _items(structure) if key_spec(k)]
-
+        # Support predicates as callable objects in the path
+        arity = _get_arity(key_spec)
+        if arity == 1:
+            # Unary predicates are called with the "key" of the path
+            # - eg a key in a mapping, an index in a sequence.
+            return [(k, v) for k, v in _items(structure) if key_spec(k)]
+        elif arity == 2:
+            # Binary predicates are called with the key and the corresponding
+            # value.
+            return [(k, v) for k, v in _items(structure) if key_spec(k, v)]
+        else:
+            # Other arities are an error.
+            raise ValueError(
+                "callable in transform path must take 1 or 2 arguments"
+            )
+
+    # Non-callables are used as-is as a key.
     return [(key_spec, _get(structure, key_spec, pmap()))]
 
 
+if signature is None:
+    def _get_arity(f):
+        argspec = getargspec(f)
+        return len(argspec.args) - len(argspec.defaults or ())
+else:
+    def _get_arity(f):
+        return sum(
+            1
+            for p
+            in signature(f).parameters.values()
+            if p.default is Parameter.empty
+            and p.kind in (Parameter.POSITIONAL_ONLY, Parameter.POSITIONAL_OR_KEYWORD)
+        )
+
 def _update_structure(structure, kvs, path, command):
     e = structure.evolver()
     if not path and command is discard:

Allow predicates on values in transform paths for pvectors and pmaps
I often want to write transformations like:

```
# Double even elements of the list
xs = pvector([1, 3, 2, 4])
assert xs.transform(lambda x: x % 2 == 0, lambda x: x * 2) == pvector([1, 3, 4, 8])
```

Particular with more complex paths:

```
xs = pmap({"foo": pvector([1, 3, 2, 4]), "bar": pvector([1, 2, 3, 4])})
assert xs.transform(
    ["foo", lambda x: x % 2 == 0],
    lambda x: x * 2,
) == pmap({"foo": pvector([1, 3, 4, 8]), "bar": pvector([1, 2, 3, 4])})
```

I can often cobble together something that deals with the above two scenarios.  It usually involves duplicating some information from the path but it's kind of manageable.

Where I really have trouble is when I want to use this missing feature twice or more within a single path:

```
xs = pmap({"foo": pvector([1, 3, 2, 4]), "bar": pvector([1, 2])})
assert xs.transform(
    [lambda (k, v): len(v) == 4, lambda x: x % 2 == 0],
    lambda x: x * 2,
) == pmap({"foo": pvector([1, 3, 4, 8]), "bar": pvector([1, 2])})
```
diff --git a/tests/transform_test.py b/tests/transform_test.py
index 490ce9b..32e1772 100644
--- a/tests/transform_test.py
+++ b/tests/transform_test.py
@@ -3,7 +3,7 @@ from pyrsistent import freeze, inc, discard, rex, ny, field, PClass
 
 def test_callable_command():
     m = freeze({'foo': {'bar': {'baz': 1}}})
-    m.transform(['foo', 'bar', 'baz'], inc) == {'foo': {'bar': {'baz': 2}}}
+    assert m.transform(['foo', 'bar', 'baz'], inc) == {'foo': {'bar': {'baz': 2}}}
 
 
 def test_predicate():
@@ -11,6 +11,32 @@ def test_predicate():
     assert m.transform(['foo', lambda x: x.startswith('b'), 'baz'], inc) == {'foo': {'bar': {'baz': 2}, 'qux': {'baz': 1}}}
 
 
+def test_broken_predicate():
+    broken_predicates = [
+        lambda: None,
+        lambda a, b, c: None,
+        lambda a, b, c, d=None: None,
+        lambda *args: None,
+        lambda **kwargs: None,
+    ]
+    for pred in broken_predicates:
+        try:
+            freeze({}).transform([pred], None)
+            assert False
+        except ValueError as e:
+            assert str(e) == "callable in transform path must take 1 or 2 arguments"
+
+
+def test_key_value_predicate():
+    m = freeze({
+        'foo': 1,
+        'bar': 2,
+    })
+    assert m.transform([
+        lambda k, v: (k, v) == ('foo', 1),
+    ], lambda v: v * 3) == {"foo": 3, "bar": 2}
+
+
 def test_remove():
     m = freeze({'foo': {'bar': {'baz': 1}}})
     assert m.transform(['foo', 'bar', 'baz'], discard) == {'foo': {'bar': {}}}

pip install -e .
parse_log_pytest
requirements.txt
pytest pytest-cov
apt-get update apt-get install -y gcc
3.9
requirements.txt
pytest --no-header -rA --tb=line --color=no -p no:cacheprovider -W ignore::DeprecationWarning
alabaster==0.7.16
babel==2.17.0
cachetools==5.5.2
certifi==2025.1.31
chardet==5.2.0
charset-normalizer==3.4.1
colorama==0.4.6
coverage==7.8.0
distlib==0.3.9
docutils==0.21.2
exceptiongroup==1.2.2
filelock==3.18.0
hypothesis==2.0.0
idna==3.10
imagesize==1.4.1
importlib_metadata==8.6.1
iniconfig==2.1.0
Jinja2==3.1.6
MarkupSafe==3.0.2
memory_profiler==0.31
packaging==24.2
platformdirs==4.3.7
pluggy==1.5.0
psutil==2.1.1
py==1.11.0
Pygments==2.19.1
pyperform==1.86
pyproject-api==1.9.0
-e git+https://github.com/tobgu/pyrsistent.git@decc5bbb11a3c795ad7553760f1bfc29f370162e#egg=pyrsistent
pytest==8.3.5
pytest-cov==6.0.0
requests==2.32.3
six==1.17.0
snowballstemmer==2.2.0
Sphinx==7.4.7
sphinx_rtd_theme==0.1.5
sphinxcontrib-applehelp==2.0.0
sphinxcontrib-devhelp==2.0.0
sphinxcontrib-htmlhelp==2.1.0
sphinxcontrib-jsmath==1.0.1
sphinxcontrib-qthelp==2.0.0
sphinxcontrib-serializinghtml==2.0.0
tomli==2.2.1
tox==4.25.0
typing_extensions==4.13.0
urllib3==2.3.0
virtualenv==20.29.3
zipp==3.21.0

name: pyrsistent
channels:
  - defaults
  - https://repo.anaconda.com/pkgs/main
  - https://repo.anaconda.com/pkgs/r
  - conda-forge
dependencies:
  - _libgcc_mutex=0.1=main
  - _openmp_mutex=5.1=1_gnu
  - ca-certificates=2025.2.25=h06a4308_0
  - ld_impl_linux-64=2.40=h12ee557_0
  - libffi=3.4.4=h6a678d5_1
  - libgcc-ng=11.2.0=h1234567_1
  - libgomp=11.2.0=h1234567_1
  - libstdcxx-ng=11.2.0=h1234567_1
  - ncurses=6.4=h6a678d5_0
  - openssl=3.0.16=h5eee18b_0
  - pip=25.0=py39h06a4308_0
  - python=3.9.21=he870216_1
  - readline=8.2=h5eee18b_0
  - setuptools=75.8.0=py39h06a4308_0
  - sqlite=3.45.3=h5eee18b_0
  - tk=8.6.14=h39e8969_0
  - tzdata=2025a=h04d1e81_0
  - wheel=0.45.1=py39h06a4308_0
  - xz=5.6.4=h5eee18b_1
  - zlib=1.2.13=h5eee18b_1
  - pip:
      - alabaster==0.7.16
      - babel==2.17.0
      - cachetools==5.5.2
      - certifi==2025.1.31
      - chardet==5.2.0
      - charset-normalizer==3.4.1
      - colorama==0.4.6
      - coverage==7.8.0
      - distlib==0.3.9
      - docutils==0.21.2
      - exceptiongroup==1.2.2
      - filelock==3.18.0
      - hypothesis==2.0.0
      - idna==3.10
      - imagesize==1.4.1
      - importlib-metadata==8.6.1
      - iniconfig==2.1.0
      - jinja2==3.1.6
      - markupsafe==3.0.2
      - memory-profiler==0.31
      - packaging==24.2
      - platformdirs==4.3.7
      - pluggy==1.5.0
      - psutil==2.1.1
      - py==1.11.0
      - pygments==2.19.1
      - pyperform==1.86
      - pyproject-api==1.9.0
      - pytest==8.3.5
      - pytest-cov==6.0.0
      - requests==2.32.3
      - six==1.17.0
      - snowballstemmer==2.2.0
      - sphinx==7.4.7
      - sphinx-rtd-theme==0.1.5
      - sphinxcontrib-applehelp==2.0.0
      - sphinxcontrib-devhelp==2.0.0
      - sphinxcontrib-htmlhelp==2.1.0
      - sphinxcontrib-jsmath==1.0.1
      - sphinxcontrib-qthelp==2.0.0
      - sphinxcontrib-serializinghtml==2.0.0
      - tomli==2.2.1
      - tox==4.25.0
      - typing-extensions==4.13.0
      - urllib3==2.3.0
      - virtualenv==20.29.3
      - zipp==3.21.0
prefix: /opt/conda/envs/pyrsistent

tests/transform_test.py::test_broken_predicate tests/transform_test.py::test_key_value_predicate
tests/transform_test.py::test_callable_command tests/transform_test.py::test_predicate tests/transform_test.py::test_remove tests/transform_test.py::test_remove_pvector tests/transform_test.py::test_remove_pclass tests/transform_test.py::test_predicate_no_match tests/transform_test.py::test_rex_predicate tests/transform_test.py::test_rex_with_non_string_key tests/transform_test.py::test_ny_predicated_matches_any_key tests/transform_test.py::test_new_elements_created_when_missing tests/transform_test.py::test_mixed_vector_and_map tests/transform_test.py::test_vector_predicate_callable_command tests/transform_test.py::test_vector_insert_map_one_step_beyond_end tests/transform_test.py::test_multiple_transformations tests/transform_test.py::test_no_transformation_returns_the_same_structure tests/transform_test.py::test_discard_multiple_elements_in_pvector
README.rst pyrsistent/_transformations.py
README.rst pyrsistent/_transformations.py