All Projects → Suor → Funcy

Suor / Funcy

Licence: bsd-3-clause
A fancy and practical functional tools

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to Funcy

Pratica
🥃 Functional Algebraic Data Types
Stars: ✭ 246 (-90.86%)
Mutual labels:  utilities, functional-programming
Ramda Adjunct
Ramda Adjunct is the most popular and most comprehensive set of functional utilities for use with Ramda, providing a variety of useful, well tested functions with excellent documentation.
Stars: ✭ 550 (-79.55%)
Mutual labels:  utilities, functional-programming
Ramda Extension
🤘Utility library for functional JavaScript. With ❤️ to Ramda.
Stars: ✭ 139 (-94.83%)
Mutual labels:  utilities, functional-programming
Bitcoin S
Bitcoin Implementation in Scala
Stars: ✭ 206 (-92.34%)
Mutual labels:  functional-programming
Swift Gen
🎱 Composable, transformable, controllable randomness.
Stars: ✭ 208 (-92.27%)
Mutual labels:  functional-programming
Bitcoin Chart Cli
Bitcoin chart for the terminal as command line util
Stars: ✭ 221 (-91.78%)
Mutual labels:  functional-programming
Wonder.js
🚀Functional, High performance 3D Webgl Engine
Stars: ✭ 225 (-91.64%)
Mutual labels:  functional-programming
Zio Actors
A high-performance, purely-functional library for building, composing, and supervising typed actors based on ZIO
Stars: ✭ 206 (-92.34%)
Mutual labels:  functional-programming
Odin
Fast & Functional logger in Scala
Stars: ✭ 225 (-91.64%)
Mutual labels:  functional-programming
React Organism
Dead simple React state management to bring pure components alive
Stars: ✭ 219 (-91.86%)
Mutual labels:  functional-programming
Nix 1p
A (more or less) one page introduction to Nix, the language.
Stars: ✭ 219 (-91.86%)
Mutual labels:  functional-programming
Hamt
Immutable and Memory-Efficient Maps and Sets in Go
Stars: ✭ 213 (-92.08%)
Mutual labels:  functional-programming
Eta
The Eta Programming Language, a dialect of Haskell on the JVM
Stars: ✭ 2,507 (-6.8%)
Mutual labels:  functional-programming
Pure Lang
Pure programming language
Stars: ✭ 209 (-92.23%)
Mutual labels:  functional-programming
Devutils App
Offline Toolbox for Developers
Stars: ✭ 2,735 (+1.67%)
Mutual labels:  utilities
Scala Exercises
The easy way to learn Scala.
Stars: ✭ 2,431 (-9.63%)
Mutual labels:  functional-programming
Gitlab Cli
Create a merge request from command line in gitlab
Stars: ✭ 224 (-91.67%)
Mutual labels:  utilities
Codejam
Set of handy reusable .NET components that can simplify your daily work and save your time when you copy and paste your favorite helper methods and classes from one project to another
Stars: ✭ 217 (-91.93%)
Mutual labels:  utilities
Silt
An in-progress fast, dependently typed, functional programming language implemented in Swift.
Stars: ✭ 217 (-91.93%)
Mutual labels:  functional-programming
Mathutilities
A collection of some of the neat math and physics tricks that I've collected over the last few years.
Stars: ✭ 2,815 (+4.65%)
Mutual labels:  utilities

Funcy Build Status

A collection of fancy functional tools focused on practicality.

Inspired by clojure, underscore and my own abstractions. Keep reading to get an overview or read the docs. Or jump directly to cheatsheet.

Works with Python 2.7, 3.4+ and pypy.

Installation

pip install funcy

Overview

Import stuff from funcy to make things happen:

from funcy import whatever, you, need

Merge collections of same type (works for dicts, sets, lists, tuples, iterators and even strings):

merge(coll1, coll2, coll3, ...)
join(colls)
merge_with(sum, dict1, dict2, ...)

Walk through collection, creating its transform (like map but preserves type):

walk(str.upper, {'a', 'b'})            # {'A', 'B'}
walk(reversed, {'a': 1, 'b': 2})       # {1: 'a', 2: 'b'}
walk_keys(double, {'a': 1, 'b': 2})    # {'aa': 1, 'bb': 2}
walk_values(inc, {'a': 1, 'b': 2})     # {'a': 2, 'b': 3}

Select a part of collection:

select(even, {1,2,3,10,20})                  # {2,10,20}
select(r'^a', ('a','b','ab','ba'))           # ('a','ab')
select_keys(callable, {str: '', None: None}) # {str: ''}
compact({2, None, 1, 0})                     # {1,2}

Manipulate sequences:

take(4, iterate(double, 1)) # [1, 2, 4, 8]
first(drop(3, count(10)))   # 13

lremove(even, [1, 2, 3])    # [1, 3]
lconcat([1, 2], [5, 6])     # [1, 2, 5, 6]
lcat(map(range, range(4)))  # [0, 0, 1, 0, 1, 2]
lmapcat(range, range(4))    # same
flatten(nested_structure)   # flat iter
distinct('abacbdd')         # iter('abcd')

lsplit(odd, range(5))       # ([1, 3], [0, 2, 4])
lsplit_at(2, range(5))      # ([0, 1], [2, 3, 4])
group_by(mod3, range(5))    # {0: [0, 3], 1: [1, 4], 2: [2]}

lpartition(2, range(5))     # [[0, 1], [2, 3]]
chunks(2, range(5))         # iter: [0, 1], [2, 3], [4]
pairwise(range(5))          # iter: [0, 1], [1, 2], ...

And functions:

partial(add, 1)             # inc
curry(add)(1)(2)            # 3
compose(inc, double)(10)    # 21
complement(even)            # odd
all_fn(isa(int), even)      # is_even_int

one_third = rpartial(operator.div, 3.0)
has_suffix = rcurry(str.endswith, 2)

Create decorators easily:

@decorator
def log(call):
    print call._func.__name__, call._args
    return call()

Abstract control flow:

walk_values(silent(int), {'a': '1', 'b': 'no'})
# => {'a': 1, 'b': None}

@once
def initialize():
    "..."

with suppress(OSError):
    os.remove('some.file')

@ignore(ErrorRateExceeded)
@limit_error_rate(fails=5, timeout=60)
@retry(tries=2, errors=(HttpError, ServiceDown))
def some_unreliable_action(...):
    "..."

class MyUser(AbstractBaseUser):
    @cached_property
    def public_phones(self):
        return self.phones.filter(public=True)

Ease debugging:

squares = {tap(x, 'x'): tap(x * x, 'x^2') for x in [3, 4]}
# x: 3
# x^2: 9
# ...

@print_exits
def some_func(...):
    "..."

@log_calls(log.info, errors=False)
@log_errors(log.exception)
def some_suspicious_function(...):
    "..."

with print_durations('Creating models'):
    Model.objects.create(...)
    # ...
# 10.2 ms in Creating models

And much more.

Dive in

Funcy is an embodiment of ideas I explain in several essays:

Running tests

To run the tests using your default python:

pip install -r test_requirements.txt
py.test

To fully run tox you need all the supported pythons to be installed. These are 2.6+, 3.3+, PyPy and PyPy3. You can run it for particular environment even in absense of all of the above:

tox -e py27
tox -e py36
tox -e lint
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].