Linking with Hydra and JSON-LD
eric.themoritzfamily.com2 pointsby ericmoritz0 comments
from itertools import imap
map(f, imap(g, imap(h, someList)))
I think Python 3's map built-in is a generator so you no longer have to use the itertools module. from itertools import ifilter
# ugly python function with a "Maybe dict" return type
def query(data, date):
"""Return the first dict where date is > x['date'] or None"""
is_greater = lambda x: date > x['date']
return next(
ifilter(
is_greater,
data
),
None
) from numpy import arange
def squares_numpy(n):
a = arange(n)
return a * a
$ python -m timeit -s "from squares import squares_append" "squares_append(1000)"
10000 loops, best of 3: 130 usec per loop
$ python -m timeit -s "from squares import squares_comprehension" "squares_comprehension(1000)"
10000 loops, best of 3: 95.4 usec per loop
$ python -m timeit -s "from squares import squares_numpy" "squares_numpy(1000)"
100000 loops, best of 3: 5.31 usec per loop 1. The evented servers are bound to one CPU, Erlang will use all CPUs
2. any bit of blocking code will stall the other code, even it just for a moment.
It is a little unfair to compare the two approaches.
After about 10 years of coding in a fit of passion we ended up with huge monolithic projects written in dynamic languages that where extremely brittle.
Fortunately languages with type inference (Rust, Golang, OCaml, Scala, etc) started becoming the answer to our problems. (We also collectively decided that Microservivces were another solution to our woes though that cargo cult is being questioned).
So we have a decade of code and packages written in Python and JavaScript that work well for our use cases (Data Science, MVP web apps/services, Database integration, etc) that is hard to give up. Often because alternatives aren't available yet in the statically typed languages (Hurry up Rust!).
There is often a lot of friction to get new languages introduced. I love Rust, but I don't think I can introduce it into our Golang/NodeJS/Javascript environment anytime soon.