Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Future.map doesn't work with dicts #64

Closed
MichaelSchneeberger opened this issue Jan 27, 2016 · 0 comments

Comments

Projects
None yet
2 participants
@MichaelSchneeberger
Copy link

commented Jan 27, 2016

The following code raises the error "string indices must be integers, not str":

import pykka
f = pykka.ThreadingFuture()
g = f.map(lambda x: x['key1'])
f.set({'key1': 3})
print g.get()

I can make it work, however, by putting the dictionary in a list:

import pykka
f = pykka.ThreadingFuture()
g = f.map(lambda x: x['key1'])
f.set( [ {'key1': 3} ] )
print g.get()

EDIT: In case the futures value is an iterable, the "map" function applies to each item consecutively. I find this unnecessary. This is has not been done for other "Future" implementations in other languages. See Scala.concurrent.Future:

def map[S](f: (T) ⇒ S)(implicit executor: ExecutionContext): Future[S]

Creates a new future by applying a function to the successful result of this future.

@jodal jodal added the bug label Jan 27, 2016

@jodal jodal added this to the v1.3 milestone Jan 27, 2016

@jodal jodal closed this in 575e6a1 Jan 22, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.