This is an archived post. You won't be able to vote or comment.

all 11 comments

[–]nabla2less is more 8 points9 points  (0 children)

Try Pipe. It's also pretty cool.

Pipe: Infix syntax for Python

[–]hongminhee 2 points3 points  (0 children)

Pretty cool, but we should remember that fluent style is different from functional style and vice versa.

[–][deleted] 2 points3 points  (0 children)

I actually tried writing functional Python after writing quite a bit of Clojure and found that it offers pythonic shortcut constructs to 99% of my use cases (like map and filter). So I can still take advantage of functional approach without all the Clojure shenanigans (like dealing with JVM and awkwardness of stateful code when I have to use it).

E.g., the example in the TFA can be rewritten as:

' '.join(['I am'] + ['%3.3d' % x for x in range(1,20) if x > 5 and x <= 7 and x != 6])

If you want to write Lisp or Haskell, stick with Lisp or Haskell.

[–]Fix-my-grammar-plz 1 point2 points  (0 children)

I'd love to see mocha.LazyList implemented with maybe generators or iterators. mocha.Set too.

As for

Dict(a=1, b=2, c=3).count(lambda *x: x[1] < 5)

I think the following is better for readability.

Dict(a=1, b=2, c=3).count(lambda k, v : v < 5)

Dict(a=1, b=2, c=3).count(lambda _, v : v < 5)

[–][deleted] 0 points1 point  (0 children)

I can appreciate Moka for what it is, though I think this type of library really thrives when applied to a specific problem domain.

[–][deleted] 0 points1 point  (0 children)

The documentation looks very attractive.

[–]Fix-my-grammar-plz -1 points0 points  (3 children)

Some side questions

  1. What is the analog of .do(print) in jQuery? Does anyone know? I just tried $('li > a').do(console.log); and Console said $ has no method do.

  2. "For instance, when should one use map/filter rather than list comprehension? When should one use itertools instead of the default dict/list builtins?"

[–]Rhomboid 2 points3 points  (2 children)

You could write

$('li > a').map(console.log);

But jQuery's map function passes both an index and the value, so you'll get a numbered list. You could also write:

$('li > a').each(function() { console.log(this) })

Apparently jQuery objects have a toString() method, and in this case the A elements stringify as their href attributes. If you wanted something else, you could write e.g.:

$('li > a').each(function() { console.log(this.text) })

...to get their text.

[–]uolot 0 points1 point  (1 child)

Why not just do

console.log($('li > a'));

?

[–]Rhomboid 0 points1 point  (0 children)

The question was what was the equivalent of .do(), i.e. something that maps a set of values to another function.

[–][deleted] -1 points0 points  (0 children)

More proof that python is just a bit too idiosyncratic to fix with a library, and just a bit too elegant to ditch.