GithubHelp home page GithubHelp logo

pipe iterator into next function about sspipe HOT 2 CLOSED

sspipe avatar sspipe commented on May 31, 2024
pipe iterator into next function

from sspipe.

Comments (2)

JoshZastrow avatar JoshZastrow commented on May 31, 2024

Actually I should have read the docs closer!

I see how [1, 2, 3, 4] | p(map, px + 1) works as list comprehension would, but I can't do dictionary comprehension or use the reduce function for that matter.

Perhaps I'm not using the library correctly?

from sspipe.

mohammad7t avatar mohammad7t commented on May 31, 2024

Thanks for your feedback.
Currently, sspipe supports p(map, px) and p(filter, px) natively, but it doesn't support p(reduce, px) natively yet. But you can use still use it with reduce like this:

>>> [1, 2, 3, 4] | p(lambda l: reduce(lambda x, y: x+y, l))
10

For dict comprehension, you can generate a list of [key, value] pairs and pass it to dict:

>>> [1, 2, 3, 4] | p(map, p([p(str), px%2])) | p(dict)
{'1': 1, '2': 0, '3': 1, '4': 0}

from sspipe.

Related Issues (13)

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.