Git Product home page Git Product logo

iterplus's Introduction

This library provides a set of functions that complement Python itertools. These include means to access iterable content via slicing, scan generator (easy series), chainable wrapper (ie. a.map(...).filter(...)) and index (returns first or last matched index in seq).

Examples

The following examples illustrate the basic usage:

Scan

fibo = scan(0, 1, lambda a, b: a + b)

"scan" returns an iterator. Note how simple it's to define series such as Fibonacci's using it. In case an explicit rule is not provided, it infers one automatically (ie. 1,2,3,...).

Sliceable

sliceable(scan(0, 1))[2:5] # returns list containing third, fourth and fifth item

"sliceable" makes it possible to slice the content of iterators.

Chainable

chainable([1, 2, 3]).map(lambda x: x * 2).filter(lambda x: x > 3).val() == [4, 6]

"chainable" makes it possible to use basic functional utilities (map, filter, reduce) using a chaining syntax.

Index

index(lambda a: a > 4, [3, 10, 8]) == 1
rindex(lambda a: a < 5, [3, 10, 8]) == 0

"index" and "rindex" make it possible to find the first or the last item of a sequence matching to a given rule.

License

iterplus is available under MIT license. See LICENSE for more details.

iterplus's People

Contributors

bebraw avatar

Watchers

James Cloos avatar  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.