Package: pyfuncol
pyfuncolpyfuncolInstallationUsageUsage without forbiddenfruitAPIDocumentationCompatibilityContributingLicenseA Python functional collections library. Itextendscollections built-in types with useful methods to write functional Python code. It usesForbidden Fruitunder the hood.pyfuncol provides:Standard "eager" methods, such asmap,flat_map,group_by, etc.Parallel methods, such aspar_map,par_flat_map, etc.Pure methods that leverage memoization to improve performance, such aspure_map,pure_flat_map, etc.Lazy methods that return iterators and never materialize results, such aslazy_map,lazy_flat_map, etc.pyfuncol can also beused without forbiddenfruit.Installationpip install pyfuncolUsageNote:If you are not using forbiddenfruit, the functions will not extend the builtins. Pleasesee herefor usage without forbiddenfruit.To use the methods, you just need to import pyfuncol. Some examples:importpyfuncol[1,2,3,4].map(lambdax:x*2).filter(lambdax:x>4)# [6, 8][1,2,3,4].fold_left(0,lambdaacc,n:acc+n)# 10{1,2,3,4}.map(lambdax:x*2).filter_not(lambdax:x<=4)# {6, 8}["abc","def","e"].group_by(lambdas:len(s))# {3: ["abc", "def"], 1: ["e"]}{"a":1,"b":2,"c":3}.flat_map(lambdakv:{kv[0]:kv[1]**2})# {"a": 1, "b": 4, "c": 9}pyfuncol provides parallel operations (for nowpar_map,par_flat_map,par_filterandpar_filter_not):[1,2,3,4].par_map(lambdax:x*2).par_filter(lambdax:x>4)# [6, 8]{1,2,3,4}.par_map(lambdax:x*2).par_filter_not(lambdax:x<=4)# {6, 8}{"a":1,"b":2,"c":3}.par_flat_map(lambdakv:{kv[0]:kv[1]**2})# {"a": 1, "b": 4, "c": 9}pyfuncol provides operations leveraging memoization to improve performance (for nowpure_map,pure_flat_map,pure_filterandpure_filter_not). These versions work only forpurefunctions (i.e., all calls to the same args return the same value) on hashable inputs:[1,2,3,4].pure_map(lambdax:x*2).pure_filter(lambdax:x>4)# [6, 8]{1,2,3,4}.pure_map(lambdax:x*2).pure_filter_not(lambdax:x<=4)# {6, 8}{"a":1,"b":2,"c":3}.pure_flat_map(lambdakv:{kv[0]:kv[1]**2})# {"a": 1, "b": 4, "c": 9}pyfuncol provides lazy operations that never materialize results:list([1,2,3,4].lazy_map(lambdax:x*2).lazy_filter(lambdax:x>4))# [6, 8]list({1,2,3,4}.lazy_map(lambdax:x*2).lazy_filter_not(lambdax:x<=4))# [6, 8]list({"a":1,"b":2,"c":3}.lazy_flat_map(lambdakv:{kv[0]:kv[1]**2}))# [("a", 1), ("b", 4), ("c", 9)]set([1,2,3,4].lazy_map(lambdax:x*2).lazy_filter(lambdax:x>4))# {6, 8}Usage without forbiddenfruitIf you are using a Python interpreter other than CPython, forbiddenfruit will not work.Fortunately, if forbiddenfruit does not work on your installation or if you do not want to use it, pyfuncol also supports direct function calls without extending builtins.frompyfuncolimportlistaspfclistpfclist.map([1,2,3],lambdax:x*2)# [2, 4, 6]APIFor lists, please refer to thedocs.For dictionaries, please refer to thedocs.For sets and frozensets, please refer to thedocs.For more details, please have a look at theAPI reference.We support all subclasses with default constructors (OrderedDict, for example).DocumentationSeehttps://pyfuncol.readthedocs.io/.CompatibilityFor functions to extend built-ins,Forbidden Fruitis necessary (CPython only).ContributingSee thecontributing guidefor detailed instructions on how to get started with the project.Licensepyfuncol is licensed under theMIT license.