hotscript icon indicating copy to clipboard operation
hotscript copied to clipboard

Working with function types

Open jasonkuhrt opened this issue 2 years ago • 3 comments

Examples:

  • Remove a union member from the return type
  • add a union member to the return type
  • remove a paramter
  • add a paramter
  • map over the paramters
  • ...

Would this be in scope for this project?

jasonkuhrt avatar May 31 '23 12:05 jasonkuhrt

Maybe a few functions like Functions.MapArguments<Mapper> and Functions.MapReturnType<Mapper> could be added to support these use cases?

type DoStuff<Fn> = Pipe<Fn, [
  // Remove a union member from the return type
  Functions.MapReturnType<Union.Exclude<"a">>,
  // add a union member to the return type
  Functions.MapReturnType<Union.Append<"b">>,
  // remove a parameter
  Functions.MapArguments<Tuples.Filter<Boolean.Extends<number>>>,
  // add a parameter
  Functions.MapArguments<Tuples.Append<"1" | "2" | "3">>,
  // map over the parameters
  Functions.MapArguments<Tuples.Map<Strings.ToNumber>>,
]>

What do you think?

gvergnaud avatar Jun 05 '23 19:06 gvergnaud

Potentially useful, yeah.

Going back to the Reselect MergeParameters example I'd linked at https://github.com/reduxjs/reselect/blob/v4.1.5/src/types.ts#L100-L148 (and the updated version from Anders Hejlsberg at https://github.com/reduxjs/reselect/blob/b2a85eeac3312bb62ae3c26bb44d9aabd8641552/src/versionedTypes/ts47-mergeParameters.ts )... what might those look like with this style of typing?

markerikson avatar Jun 05 '23 20:06 markerikson

Added Functions.MapParameters and Functions.MapReturnType to the latest release! let me know what you think

gvergnaud avatar Jul 03 '23 09:07 gvergnaud