fnc - Functional Programming Utilities

0.5.3 · maintenance · verified Fri Apr 17

fnc is a Python library that provides functional programming utilities, primarily focusing on working with generators and iterable data. It offers curried versions of common functions like `map`, `filter`, and `pipe` for a more declarative style. The current version is 0.5.3, released in October 2021, and the project is in a maintenance mode with infrequent updates.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates the use of `pipe` for chaining functional operations and how curried functions like `map` and `filter` are applied.

from fnc import pipe, map, filter, take

data = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

# Example 1: Use pipe for a functional chain
result_pipe = pipe(
    data,
    map(lambda x: x * 2),     # Double each number
    filter(lambda x: x > 10), # Keep only numbers greater than 10
    take(3),                  # Take the first 3 results
    list                      # Materialize the generator into a list
)

print(f"Result with pipe: {result_pipe}") # Expected: [12, 14, 16]

# Example 2: Curried map and filter manually
double = map(lambda x: x * 2)
odd = filter(lambda x: x % 2 != 0)

processed_data = double(odd(data)) # Apply odd filter, then double
print(f"Manual curried chain: {list(processed_data)}") # Expected: [2, 6, 10, 14, 18]

view raw JSON →