3 ms·
Partial application makes sense to me as a useful computer science concept. Reasoning about functions when they always have 1-arity makes proofs possible. In
by gorgoiler 3y ago
Partial application makes sense to me as a useful computer science concept. Reasoning about functions when they always have 1-arity makes proofs possible.
In software though, it just seems like code golf for people who can’t or won’t write a function as a way of sharing code between call sites:
def serialize(fn, data, path):
…
yamlize = partial(
serialize,
yaml.dump
)
jsonize = partial(
serialize,
json.dumps
)
Presumably some of these people wake up in a cold sweat about the shame of typing “partial(serialize, …)” twice and do this:
def serialize(fn, data, path):
…
a = lambda f: partial(serialize, f)
yamlize = a(yaml.dump)
jsonize = a(json.dumps)
A good example of Don’t Repeat Yourself mutating into Never Repeat Yourself with ill effect, because the developer has self flagellated so much that the following code is deemed to have too much repetition in it:
def write(data, path):
…
def write_yaml(data, path):
write(yaml.dump(data), path)
def write_json(data, path):
write(json.dumps(data), path)