z-pattern-matching / z

Pattern Matching for Javascript
https://z-pattern-matching.github.io/
Apache License 2.0
1.72k stars 50 forks source link

Flip around order of arguments #51

Open masaeedu opened 6 years ago

masaeedu commented 6 years ago

Thank you for a very useful library. It's a bit late to bring this up I think, but I thought I'd open an issue anyway; it seems like the current order of arguments is not great for partial application. From the README examples:

const compress = (numbers) => {
  return matches(numbers)(
    (x, y, xs) => x === y
      ? compress([x].concat(xs))
      : [x].concat(compress([y].concat(xs))),
    (x, xs) => x // stopping condition
  )
}

but if it accepted the case matchers first, it could just be:

const compress = matches(
  (x, y, xs) => x === y
    ? compress([x].concat(xs))
    : [x].concat(compress([y].concat(xs))),
  (x, xs) => x // stopping condition
)

It's not hard to define a flipped around version wherever I use it, but it'd be handy if the library just exported a different version of matches that took arguments in that order.

leonardiwagner commented 5 years ago

going to release a v2 for such breaking change