Closed pxeger closed 2 years ago
This doesn't seem cursed enough for Whython. It'd be nice and cursed if accessing attributes of functions that didn't exist instead tried to do function composition (i.e. f.g
was lambda x:f(g(x))
if f
doesn't have an attribute g
).
There is a very narrow goldilocks zone of what is "cursed enough" for Whython. I want to add things that do actually seem like a good idea on the surface, but in fact cause lots of bad practice and/or would make Python an inconsistent language as a whole.
Make calls that are missing args into partials? Create a new singleton sentinel NoArg to signify a missing arg to a partial. If you can create "NoArg", then you can make args that have no default always default to NoArg.
a = print(NoArg,end="\n\n-said the cat\n")
a("Meow. Feed Me.")
#Meow. Feed Me.
#
#-said the cat
def b(animal,sound):
print(f"{animal} goes {sound}")
c = b("Cat")
c("Meow")
#Cat goes Meow
c("Purr")
#Cat goes Purr
Make itertools.chain an operator?? (+ is just lurking in the corner waiting to become the chosen one, or you could hijack a logical comparison like 'and' :D )
Not exactly composition, but while we're messing with functions, drop map and make iterables callable, taking a Function. This may be crossing over into insanity, but a two arg function passed to an iterable could be treated as a reduce.....
ugh and calling a string with non-function args could eval it as the body of a lambda and pass in the given args as a,b,c,d... or kwarg keys.
Why not?
Please open these as separate issues; they are not directly related to function composition
Done!
I was thinking either
f@g
(__matmul__
) for maximum stupidity, orf[g]
for actual usability (because of precedence, if you want to immediately call it afterwards).