Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@twop
Copy link
Contributor

@twop twop commented Apr 7, 2018

  • Added reverseCurry function that is based on number of arguments + works via arguments
function reverseCurry<A1, A2, R, F extends (a1: A1, a2: A2) => R>(
  f: F,
): ReverseCurriedFunc<A1, A2, R> {
  const func = function reverseCurried(a1: A1 | A2, a2: A2 | undefined) {
    if (arguments.length == 1) {
      return (a: A1) => f(a, <A2>a1);
    }

    return f(<A1>a1, <A2>a2);
  };

  return (func as any) as ReverseCurriedFunc<A1, A2, R>;
}
  • Also replaced match with evalMatch -> reverseCurry(evalMatch)
  • Added tests for inline matching

@coveralls
Copy link

coveralls commented Apr 7, 2018

Coverage Status

Coverage remained the same at 100.0% when pulling fd4cab3 on twop:master into 219b15e on pelotom:master.

@twop
Copy link
Contributor Author

twop commented Apr 7, 2018

BTW thanks for adding prettier. It was a huge pain for me to remove ';' all the time :)

  • I have changes ready for update & config will make PR after this is merged (if merged at all :) )

src/index.ts Outdated
: cases.default(variant);
}

const match: ReverseCurriedFunc<any, any, any> = reverseCurry(evalMatch);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All this reverse curry machinery seems overly complex. Why not just

  const match = (first: any, second?: any) =>
    second ? evalMatch(first, second) : (variant: any) => evalMatch(variant, first);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I originally used it "update" func as well. But I guess if we rely on ts to exclude 'undefine' we simplify that.

@twop
Copy link
Contributor Author

twop commented Apr 8, 2018

Used suggested variant

@pelotom pelotom merged commit 7d7c17e into pelotom:master Apr 8, 2018
@pelotom
Copy link
Owner

pelotom commented Apr 8, 2018

Great, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants