Giter Club home page Giter Club logo

transducers-python's Introduction

transducers-python

Transducers are composable algorithmic transformations. They are independent from the context of their input and output sources and specify only the essence of the transformation in terms of an individual element. Because transducers are decoupled from input or output sources, they can be used in many different processes - collections, streams, channels, observables, etc. Transducers compose directly, without awareness of input or creation of intermediate aggregates.

In Python you can transduce anything you can iterate over (the implementation of reduce included uses a for loop). This includes generators and coroutines in addition to the vast majority of Python collections. See below for an example of transducing over a generator.

For more information about Clojure transducers and transducer semantics see the introductory blog post and this video.

transducers-python is brought to you by Cognitect Labs.

Installation

pip install --use-wheel --pre transducers

Compatibility

transducers-python is compatible with Python 2.7.8, Python 3.X, and PyPy. It may be compatible with other Python Implementations as well.

Documentation

API documentation can be found here.

Usage

import transducers as T
from fractions import Fraction

def geometric_series(a, r):
    power = 0
    yield a
    while True:
        power += 1
        yield a * r**power

T.transduce(T.compose(T.take(3), T.map(float)),
            T.append,
            [],
            geometric_series(Fraction(1, 1), Fraction(1, 2)))

# > [1.0, 0.5, 0.25]

For more examples of use, see the test suite tests/transducer_tests.py.

Contributing

This library is open source, developed internally by Cognitect. Issues can be filed using GitHub Issues.

This project is provided without support or guarantee of continued development. Because transducers-python may be incorporated into products or client projects, we prefer to do development internally and do not accept pull requests or patches.

Copyright and License

Copyright © 2014 Cognitect

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

transducers-python's People

Contributors

benkamphaus avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.