Coder Social home page Coder Social logo

fmap's Introduction

fmap

Lazy map for Iterable and Sequence

Install

pip install git+https://github.com/betafcc/fmap.git

What?

In Python 2

Only eager evaluation:

> range(1, 11)
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]  # bad

> range(1, 11)[5:6]
[6]  # bad

> def fib(x):
.     if x in [0, 1]: return x
.     return fib(x - 1) + fib(x - 2)
> map(fib, range(1, 101))[30]
...  # End of the universe, really bad
In Python 3

Lazy evaluation, but losing the interface:

> range(1, 11)
range(1, 11)  # good

> range(1, 11)[5:6]
range(6, 7)  # really good

> map(fib, range(1, 101))
<map at 0x7f12881fe0>  # meh

> map(fib, range(1, 101))[30]
TypeError: 'map' object is not subscriptable  # bad
With fmap

Lazy evaluation, preserving the interface:

> from fmap import fmap
> fmap(fib, range(1, 101))
fmap(fib, range(1, 101))  # good

> fmap(fib, range(1, 101))[20:80]
fmap(fib, range(21, 81))  # really good

> fmap(fib, range(1, 101))[30]
1346269  # awesome
Also

Convenience for composition, fusing the functions:

> def sq(x): return x*x
> fmap(sq, fmap(fib, range(1, 101)))
fmap(sq . fib, range(1, 101))

> fmap(fib, range(1, 101)) | sq
fmap(sq . fib, range(1, 101))

fmap's People

Contributors

betafcc avatar

Stargazers

Suhas Kashyap avatar Saulo Lordão avatar

Watchers

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