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

TypeScript typings #154

Open
otbe opened this issue Mar 6, 2017 · 5 comments
Open

TypeScript typings #154

otbe opened this issue Mar 6, 2017 · 5 comments

Comments

@otbe
Copy link

otbe commented Mar 6, 2017

Hi everyone,

I would love to have typings for ramda-fantasy. Ramda itself has typings. I noticed that folktale also has no typings. Is there any reason why there are no type definitions available? Its just because nobody uses ramda/ramds-fantasy with TS?

Thanks!

@buzzdecafe
Copy link
Member

i am sure some would find TS useful. no reason they should not exist

@otbe
Copy link
Author

otbe commented Mar 6, 2017

Good to know :)

Ive started working on some typings, but Im new to ramda/ramda-fantasy (and fp in general) so I may need your help :)

declare module 'ramda-fantasy' {
  import { CurriedFunction2 } from 'ramda';

  interface Future<E, A>  {
    fork(reject: (v: E) => void, resolve: (v: A) => void): void;
    ap(f: any): any;
    map<A2>(fb: (e: A) => A2): Future<E, A2>;
    bimap<E2, A2>(errFn: (value: E) => E2, successFn: (value: A) => A2): Future<E2, A2>;
    chain<A2>(fn: (v: A) => Future<E, A2>): Future<E, A2>;
    chainReject<A2>(fn: (value: E) => Future<E, A2>): Future<E, A2>;
  }

  interface FutureStatic {
    <E, A>(fn: (reject: (v: E) => void, resolve: (v: A) => void) => void): Future<E, A>
    new <E, A>(fn: (reject: (v: E) => void, resolve: (v: A) => void) => void): Future<E, A>;
    cache<E, A>(f: Future<E, A>): Future<E, A>;
    of<E, A>(x: A): Future<E, A>;
    reject<E, A>(val: E): Future<E, A>;
  }

  export const Future: FutureStatic;

  interface IO<T> {
    ap<T2, T3>(thatIo: IO<T2>): IO<T3>;
    chain<T2>(fn: (value: T) => IO<T2>): IO<T2>;
    map<T2>(fn: (value: T) => T2): IO<T2>;
    runIO(): T;
  }

  interface IOStatic {
    <T>(fn: () => T): IO<T>;
    new <T>(fn: () => T): IO<T>;
    of<T>(x: T): IO<T>;
    runIO<T>(io: IO<T>): T;
  }

  export const IO: IOStatic;

  interface Identity<T> {
    ap<T2, T3>(app: Identity<T2>): Identity<T3>;
    chain<T2>(fn: (value: T) => Identity<T2>): Identity<T2>;
    map<T2>(fn: (value: T) => T2): Identity<T2>;
  }

  interface IdentityStatic {
    <T>(value: T): Identity<T>;
    new <T>(value: T): Identity<T>;
    of<T>(x: T): Identity<T>;
  }

  export const Identity: IdentityStatic;


  interface Either<L, R> {
    chain<L2, R2, T>(f: (e: Either<L2, R2>) => T): Either<L2, T>;
    ap<R2>(f: (e: R) => Either<L, R2>): Either<L, R2>;
    extend<L2, R2, T>(f: (e: Either<L2, R2>) => T): Either<L2, T>;
    equals<L2, R2>(that: Either<L2, R2>): boolean;
    bimap<L2, R2>(lf: (value: L) => L2, rf: (value: R) => R2): Either<L2, R2>;
    map<T>(fn: (e: R) => T): Either<L, T>;
  }

  interface EitherStatic {
    Left<L, R>(value: L): Either<L, R>;
    Right<L, R>(value: R): Either<L, R>;
    either<L, R, T>(left: (value: L) => T, right: (value: R) => T, e: Either<L, R>): T;
    either<L, R, T>(left: (value: L) => T, right: (value: R) => T):  (e: Either<L, R>) => T;
    either<L, R, T>(left: (value: L) => T): CurriedFunction2<(value: R) => T, Either<L, R>, T>;
    isLeft<L, R>(x: Either<L, R>): boolean;
    isRight<L, R>(x: Either<L, R>): boolean;
    of<L, R>(value: R): Either<L, R>;
  }

  export const Either: EitherStatic;

  interface Maybe<T> {
    getOrElse(value: T): T;
    map<T2>(fn: (vlaue: T) => T2): Maybe<T2>;
    ap<T2>(m: Maybe<T>): Maybe<T2>;
    chain<T2>(fn: (value: T) => Maybe<T2>): Maybe<T2>;
    // reduce(fn: ());
    equals<T2>(m: Maybe<T2>): boolean;
  }

  interface MaybeStatic {
    Just<T>(value: T): Maybe<T>;
    Nothing<T>(): Maybe<T>;
    isJust<T>(x: Maybe<T>): boolean;
    isNothing<T>(x: Maybe<T>): boolean;
    maybe<T, T2>(seed: T2, fn: (value: T) => T2, m: Maybe<T>): T2;
    maybe<T, T2>(seed: T2, fn: (value: T) => T2): (m: Maybe<T>) => T2;
    maybe<T, T2>(seed: T2): CurriedFunction2<(value: T) => T2, Maybe<T>, T2>;
    of<T>(x: T): Maybe<T>;
  }

  export const Maybe: MaybeStatic;
}

I dont know if this is the right way at all :/

@arrterian
Copy link

@otbe, Hello! Nice job. Can you publish your typings in dt~ repository?

@otbe
Copy link
Author

otbe commented Mar 19, 2017

Hi @RomanValihura, please feel free to use or publish it on you own :)
I stopped using ramda/ramda-fantasy together with TypeScript atm.

@piq9117
Copy link

piq9117 commented Apr 2, 2017

cant this be a PR and be in a type-definition directory?

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

No branches or pull requests

4 participants