Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add generic function #177

Closed
wants to merge 1 commit into from

Conversation

amir-arad
Copy link

I've added a generic function with variable amount of arguments. It's something I need in my work for function chaining, adaptors and such.

Issues:

  1. type NumberToString should move to typelevel-ts project IMO
  2. I couldn't find a way to get rid of the first generic param I. It looks like it's redundant, as the size of the tuple is already in the A param.
    I've tried these things:
type TupleLength<T, I = 0> = {
    'true': TupleLength<T, Increment[I]>
    'false': I
}[ObjectHasKey<T, I>]
type GFunction2<A, R=void> = GFunction<TupleLength<A>, A, number>;
type GFunction3<A, R=void, I=0> = GFunction<TupleLength<A, I>, A, number>;

and also

export type GFunction<A extends Array<any>, R=void> =
    If<ObjectHasKey<A, '1'>,
        Function2<A[0], A[1], R>,
        If<ObjectHasKey<A, '0'>,
            Function1<A[0], R>,
            Lazy<R>>>

would welcome any ideas...

@SimonMeskens
Copy link
Collaborator

I did some initial tests and it's perfectly possible to get rid of the first generic parameter. The code is kinda complex though, it seems. I'll report back if I find a solution I like.

@gcanti
Copy link
Owner

gcanti commented Jul 26, 2017

Interesting topic, thanks for this PR @amir-arad, though it seems more related to typelevel-ts than fp-ts, please open an issue there if you find a good solution

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