All Projects → didactic-meme → pyfuncol

didactic-meme / pyfuncol

Licence: MIT license
Functional collections extension functions for Python

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to pyfuncol

trembita
Model complex data transformation pipelines easily
Stars: ✭ 44 (+37.5%)
Mutual labels:  functional, parallel, collections
Funky
Funky is a functional utility library written in Objective-C.
Stars: ✭ 41 (+28.13%)
Mutual labels:  functional, collections
Eclipse Collections
Eclipse Collections is a collections framework for Java with optimized data structures and a rich, functional and fluent API.
Stars: ✭ 1,828 (+5612.5%)
Mutual labels:  functional, collections
Rangeless
c++ LINQ -like library of higher-order functions for data manipulation
Stars: ✭ 148 (+362.5%)
Mutual labels:  functional, parallel
Cloe
Cloe programming language
Stars: ✭ 398 (+1143.75%)
Mutual labels:  functional, parallel
ugo
Simple and expressive toolbox written in Go
Stars: ✭ 27 (-15.62%)
Mutual labels:  functional, collections
Parallel-NDJSON-Reader
Parallel NDJSON Reader for Python
Stars: ✭ 13 (-59.37%)
Mutual labels:  parallel
Galaxy
Galaxy is an asynchronous parallel visualization ray tracer for performant rendering in distributed computing environments. Galaxy builds upon Intel OSPRay and Intel Embree, including ray queueing and sending logic inspired by TACC GraviT.
Stars: ✭ 18 (-43.75%)
Mutual labels:  parallel
pareach
a tiny function that "parallelizes" work in NodeJS
Stars: ✭ 19 (-40.62%)
Mutual labels:  parallel
kanji
A strongly typed GraphQL API framework
Stars: ✭ 12 (-62.5%)
Mutual labels:  functional
rTRNG
R package providing access and examples to TRNG C++ library
Stars: ✭ 17 (-46.87%)
Mutual labels:  parallel
ParsecSharp
The faster monadic parser combinator library for C#
Stars: ✭ 23 (-28.12%)
Mutual labels:  functional
codeceptjs-bdd
⭐️ ⭐️⭐️ Migrated to Salesforce Open Source Platform - https://github.com/salesforce/codeceptjs-bdd
Stars: ✭ 24 (-25%)
Mutual labels:  parallel
lunala
💎│ The official Lunala's source code! Yet a modern space exploration bot.
Stars: ✭ 24 (-25%)
Mutual labels:  functional
noroutine
Goroutine analogue for Node.js, spreads I/O-bound routine calls to utilize thread pool (worker_threads) using balancer with event loop utilization. 🌱
Stars: ✭ 86 (+168.75%)
Mutual labels:  parallel
fn
Functional library for PHP with proper currying
Stars: ✭ 22 (-31.25%)
Mutual labels:  functional
raptor
General, high performance algebraic multigrid solver
Stars: ✭ 50 (+56.25%)
Mutual labels:  parallel
quagmire
Python surface process framework on highly scalable unstructured meshes
Stars: ✭ 13 (-59.37%)
Mutual labels:  parallel
bascomtask
Lightweight parallel Java tasks
Stars: ✭ 49 (+53.13%)
Mutual labels:  parallel
typed-prelude
Reliable, standards-oriented software for browsers & Node.
Stars: ✭ 48 (+50%)
Mutual labels:  functional

pyfuncol

CI codecov PyPI Downloads Documentation Status GitHub license

A Python functional collections library. It extends collections built-in types with useful methods to write functional Python code. It uses Forbidden Fruit under the hood.

pyfuncol provides:

  • Standard "eager" methods, such as map, flat_map, group_by, etc.
  • Parallel methods, such as par_map, par_flat_map, etc.
  • Pure methods that leverage memoization to improve performance, such as pure_map, pure_flat_map, etc.
  • Lazy methods that return iterators and never materialize results, such as lazy_map, lazy_flat_map, etc.

pyfuncol can also be used without forbiddenfruit.

Installation

pip install pyfuncol

Usage

Note: If you are not using forbiddenfruit, the functions will not extend the builtins. Please see here for usage without forbiddenfruit.

To use the methods, you just need to import pyfuncol. Some examples:

import pyfuncol

[1, 2, 3, 4].map(lambda x: x * 2).filter(lambda x: x > 4)
# [6, 8]

[1, 2, 3, 4].fold_left(0, lambda acc, n: acc + n)
# 10

{1, 2, 3, 4}.map(lambda x: x * 2).filter_not(lambda x: x <= 4)
# {6, 8}

["abc", "def", "e"].group_by(lambda s: len(s))
# {3: ["abc", "def"], 1: ["e"]}

{"a": 1, "b": 2, "c": 3}.flat_map(lambda kv: {kv[0]: kv[1] ** 2})
# {"a": 1, "b": 4, "c": 9}

pyfuncol provides parallel operations (for now par_map, par_flat_map, par_filter and par_filter_not):

[1, 2, 3, 4].par_map(lambda x: x * 2).par_filter(lambda x: x > 4)
# [6, 8]

{1, 2, 3, 4}.par_map(lambda x: x * 2).par_filter_not(lambda x: x <= 4)
# {6, 8}

{"a": 1, "b": 2, "c": 3}.par_flat_map(lambda kv: {kv[0]: kv[1] ** 2})
# {"a": 1, "b": 4, "c": 9}

pyfuncol provides operations leveraging memoization to improve performance (for now pure_map, pure_flat_map, pure_filter and pure_filter_not). These versions work only for pure functions (i.e., all calls to the same args return the same value) on hashable inputs:

[1, 2, 3, 4].pure_map(lambda x: x * 2).pure_filter(lambda x: x > 4)
# [6, 8]

{1, 2, 3, 4}.pure_map(lambda x: x * 2).pure_filter_not(lambda x: x <= 4)
# {6, 8}

{"a": 1, "b": 2, "c": 3}.pure_flat_map(lambda kv: {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(lambda x: x * 2).lazy_filter(lambda x: x > 4))
# [6, 8]

list({1, 2, 3, 4}.lazy_map(lambda x: x * 2).lazy_filter_not(lambda x: x <= 4))
# [6, 8]

list({"a": 1, "b": 2, "c": 3}.lazy_flat_map(lambda kv: {kv[0]: kv[1] ** 2}))
# [("a", 1), ("b", 4), ("c", 9)]

set([1, 2, 3, 4].lazy_map(lambda x: x * 2).lazy_filter(lambda x: x > 4))
# {6, 8}

Usage without forbiddenfruit

If 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.

from pyfuncol import list as pfclist

pfclist.map([1, 2, 3], lambda x: x * 2)
# [2, 4, 6]

API

For lists, please refer to the docs.

For dictionaries, please refer to the docs.

For sets and frozensets, please refer to the docs.

For more details, please have a look at the API reference.

We support all subclasses with default constructors (OrderedDict, for example).

Documentation

See https://pyfuncol.readthedocs.io/.

Compatibility

For functions to extend built-ins, Forbidden Fruit is necessary (CPython only).

Contributing

See the contributing guide for detailed instructions on how to get started with the project.

License

pyfuncol is licensed under the MIT license.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].