
Security News
npm ‘is’ Package Hijacked in Expanding Supply Chain Attack
The ongoing npm phishing campaign escalates as attackers hijack the popular 'is' package, embedding malware in multiple versions.
A library to inject common functional programming operations as methods into iterable objects.
A library to inject common functional programming operations as methods
into iterable objects. Currently, it injects
filter, flat_map, foldl, foldr, map,
and reduce
operations along
with sum, count, any, all, max, min,
and zip
operations.
The library can be installed via pip install funcipy
. Similarly, it
can be uninstalled via pip uninstall funcipy
.
When you want to inject common functional programming operations as
methods into an object Obj, invoke funcipy.funcify
function with
Obj as the argument. If Obj is iterable, then the function will
return an object that
Otherwise, Obj is returned as is.
Here are few example invocations.
.. code:: python
from funcipy import funcify
import functools
import itertools
import operator
i = range(5, 15)
print("Map function: " + ' '.join(map(str, i)))
tmp1 = funcify(i)
print("Map function applied to funcified object: " + ' '.join(map(str, tmp1)))
print("Map method: " + ' '.join(tmp1.map(str)))
print("Map and Filter Method chaining: " +
' '.join(tmp1.filter(lambda x: x % 2).map(str)))
print("Reduce function: " + str(functools.reduce(operator.add, i, 5)))
print("Reduce method: " + str(tmp1.reduce(operator.add, 5)))
print("Reduce function: " + str(functools.reduce(operator.sub, i)))
print("Foldl method: " + str(tmp1.foldl(operator.sub)))
print("Foldr method: " + str(tmp1.foldr(operator.sub)))
print("Flat-map operation: " + ' '.join(itertools.chain.from_iterable(
map(str, i))))
print("Flat-map method: " + ' '.join(funcify(i).flat_map(str)))
print("Sum function: " + str(sum(i)))
print("Sum method: " + str(tmp1.sum()))
print("Count function: " + str(sum(1 for _ in filter(lambda x: x > 10, i))))
print("Count method: " + str(tmp1.count(lambda x: x > 10)))
print("Max function: " + str(max(i)))
print("Max method: " + str(tmp1.max()))
print("Min function: " + str(min(i)))
print("Min method: " + str(tmp1.min()))
print("Any function: " + str(any(map(lambda x: x > 10, i))))
print("Any method: " + str(tmp1.map(lambda x: x > 10).any()))
print("All function: " + str(all(map(lambda x: x > 10, i))))
print("All method: " + str(tmp1.map(lambda x: x > 10).all()))
j = range(0, 7)
print("Zip function: " + ' '.join(map(str, zip(i, j))))
print("Zip method: " + ' '.join(tmp1.zip(j).map(str)))
Copyright (c) 2017, Venkatesh-Prasad Ranganath
Licensed under BSD 3-clause "New" or "Revised" License (https://choosealicense.com/licenses/bsd-3-clause/)
Authors: Venkatesh-Prasad Ranganath
FAQs
A library to inject common functional programming operations as methods into iterable objects.
We found that funcipy demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
The ongoing npm phishing campaign escalates as attackers hijack the popular 'is' package, embedding malware in multiple versions.
Security News
A critical flaw in the popular npm form-data package could allow HTTP parameter pollution, affecting millions of projects until patched versions are adopted.
Security News
Bun 1.2.19 introduces isolated installs for smoother monorepo workflows, along with performance boosts, new tooling, and key compatibility fixes.