Yeah if you change the API to be a bit more powerful, you could build all kinds of ideas on top of the basic kernel of idea...

Here's some others I was shooting around with a python-eque buddy of mine this morning:
@curry_helper
def is_(x):
... # elsewhere

@is_.add_predicate
def a_number(x):
return isinstance(x, float)

@is_.add_predicate
def an_instance_of(x, y):
return isinstance(x, y)
Then you can say:

is_(x).a_number()
is_(x).an_instance_of(y)

Or you could also do:

@curry_helper
def insert(arg):
... # elsewhere

@insert.add_predicate
def into(obj, cls):
if not isinstance(obj, cls):
raise TypeError(f"{type(obj).__qualname__}")

@insert.into.add_predicate(obj='m', cls=MutableMapping)
def mapping(k, v, m):
if k in m:
raise KeyError(f"{k!r} already exists")
m[k] = v

@insert.add_predicate(obj='s', cls=MutableSequence)
def seq(x, s):
... # elsewhere

@insert.seq.add_predicate(x='x', s='s')
def at(x, s, i):
s.insert(i, x)
The idea there would be to provide a way to pass arguments to parent functions, and then:
insert(x).into.seq(s).at(i)
insert(k, v).into.mapping(m)
I would never use any of this in a serious application, but it's still fun.

---
Ricky.

"I've never met a Kentucky man who wasn't either thinking about going home or actually going home." - Happy Chandler


On Mon, Oct 18, 2021 at 12:27 PM Mathew Elman <mathew.elman@ocado.com> wrote:
This is interesting, it's not as nice as native syntax support could have been but a decorator like this is also pretty nice.
I think I would bikeshed this so the decorator was the full dot separated signature, e.g.

@curry_helper('insert.into')
def insert(x: Any, y: list):
    def y.append(x)

but other than that, I think this is probably the closest thing I'll get out of this, so thanks.
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-leave@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/NBMWJ54XSI6JQESR7ZXUR4WFYW7GNHU4/
Code of Conduct: http://python.org/psf/codeofconduct/