News for hackers. Stuff that matters.
Re:Map/Reduce for Mortals by lalaithion on Tuesday January 14, 2020 @12:49PM (#22047208)
Having pointfree functions and curried application makes the functional example more readable, as it removes the obscuring lambdas:

    (reduce (+) . map (^2) . filter ((==1).(%3))) [1,2,3,4,5]
The above is pseudo-Haskell. If we want to
Re:Map/Reduce for Mortals by lgas on Tuesday January 14, 2020 @02:36PM (#22048411)
In actual Haskell I would write it as

    sum [ n^2 | n <- [1..5], n % 3 == 1 ]
which seems to express the idea fairly directly and I'm fairly sure has a close analog in python.
Re:Map/Reduce for Mortals by lightsighter on Tuesday January 14, 2020 @03:28PM (#22048924)
python: sum([n * n for n in range(1,5,3)])
Re:Map/Reduce for Mortals by marai2 on Tuesday January 14, 2020 @05:30PM (#22049904)
haskell: sum [n^2 | n <- [1,3..5]]

I just remembered haskell's "range" operator ".." can also take a step size.

['a', 'd' .. 'z'] => "adgjmpsvy"

Re:Map/Reduce for Mortals by 1-more on Tuesday January 14, 2020 @01:19PM (#22047611)
yeah to me this just hollers for the kind of "pour it through the functions" approach we see in functional languages or even with Ramda.pipe in JS. Ezpz.
Re:Map/Reduce for Mortals by adamch on Tuesday January 14, 2020 @02:18PM (#22048239)
Or in functional rust

  (1..5)
    .into_iter()
    .filter(|i| i % 3 == 1)
    .map(|i| i * i)
    .sum();
I don't know if we really need a new syntax for map reduce.
Re:Map/Reduce for Mortals by crooked-v on Tuesday January 14, 2020 @03:18PM (#22048832)
That's also basically the same syntax as doing it in JS, aside from the lack of builtins:

    import { range } from 'ramda';

    range(1, 6)
      .filter(i => i % 3 === 1)
      .map(i => i * i)
      .reduce((a, b) => a + b, 0);
Or, if you're using the pipeline operator (experimental, stage 1, nobody can quite decide on exactly the syntax but this gives the rough idea):

    import { range, sum } from 'ramda';

    range(1, 6)
      |> x => x.filter(i => i % 3 === 1)
      |> x => x.map(i => i * i)
      |> sum
Re:Map/Reduce for Mortals by 1-more on Wednesday January 15, 2020 @11:03AM (#22055356)
We can get rid of these arrows using ramda's curried list functions, at the expense of being slower and harder to read but making us feel more clever:

  pipe(
    range,
    filter(pipe(
      modulo(__, 3), // x => x % 3
      equals(1) // y => y === 1
    )),
    map(flip(Math.pow)(2)),
    sum
  )(1,6)