News for hackers. Stuff that matters.
Re:Coconut – Pythonic functional programming language by jpulec on Thursday June 23, 2016 @01:26PM (#11962792)
I think lambda syntax can be a bit cumbersome, but that aside what I really miss is a clean syntax for chaining functional operations. So often I find myself thinking about data in terms of 'pipelines'. i.e. in JS:

  _.chain(values)
   .map(() => {})
   .flatten()
   .compact()
   .uniq()
   .value()
vs Python where doing the same thing becomes either a nested mess of function calls or comprehensions or a for loop.
Re:Coconut – Pythonic functional programming language by SoftwareMaven on Thursday June 23, 2016 @01:40PM (#11962921)
But that's a function of API, not the language itself. Django (and most ORMs, I believe) support that kind of behavior:

    MyTable.objects.
        filter(some_row__gt=5).
        exlude(other_row='q').
        order_by('other_row')
The Python iterable APIs have decided to use nesting rather than chaining, but you can still have an underscore-like API: https://github.com/serkanyersen/underscore.py

The bigger problem remains: lambda functions are hideous in Python. map() will forever be ugly if you try to use it in the same way it is used in most functional languages.

Re:Coconut – Pythonic functional programming language by chris_7 on Thursday June 23, 2016 @02:05PM (#11963120)
This sort of API is hard to implement in Python though, because there's no formal notion of interfaces, so you cannot extend all iterables generically. So you need to use free functions (which don't read well when chained) or a wrapper object (ick).
Re:Coconut – Pythonic functional programming language by moosingin3space on Thursday June 23, 2016 @08:08PM (#11965247)
Elixir and F# have my favorite syntax for that:

    values |> map(&({})) |> flatten |> compact |> uniq
Although, the closure syntax is a little clunky before you get used to it.
Re:Coconut – Pythonic functional programming language by Bromskloss on Thursday June 23, 2016 @05:51PM (#11964558)
I've been thinking that it might be nice to use chaining (though I didn't know it had a name) in ordinary mathematical notation too, writing "x f g" instead of "g(f(x))".
Re:Coconut – Pythonic functional programming language by hcrisp on Thursday June 23, 2016 @02:32PM (#11963325)
You don't like using pytoolz? Pseudocode:

    result = pytoolz.pipe(values, map, flatten, compact, uniq, value)
    # or
    func = pytoolz.compose(value, uniq, compact, flatten, map)
    results = func(values)
Re:Coconut – Pythonic functional programming language by Bromskloss on Thursday June 23, 2016 @05:55PM (#11964577)
Looks interesting. How do you tell map what function to use?
Re:Coconut – Pythonic functional programming language by hcarvalhoalves on Thursday June 23, 2016 @11:06PM (#11966003)
You probably need `compose(foo, partial(map, fn), bar)`.
Re:Coconut – Pythonic functional programming language by hcrisp on Friday June 24, 2016 @12:31AM (#11966463)
Yeah, you do this or use curried version:

    pytoolz.curried.map(fn)