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

Prelude file #952

Closed
kirillt opened this issue Sep 13, 2019 · 2 comments
Closed

Prelude file #952

kirillt opened this issue Sep 13, 2019 · 2 comments

Comments

@kirillt
Copy link

kirillt commented Sep 13, 2019

🚀 Feature request

Hi guys, the project is awesome, but for newcomers from other FP languages would be much easier to start coding if there was some Prelude file with all basic types and combinators, like Array, Option, map, flatMap, filter, find, etc. This would drammatically decrease effort necessary to adapt to new syntax, would remove necessity to grep the repo to find how to apply, for instance, Filterable type class. This is all basic stuff which usually works out-of-the-box in Scala or Haskell without any imports.

Current Behavior

Necessary to import a lot of files to write something like this (in plain TS):

let xs: number[] = [1,2,3,4,5,6,7];

let result = xs
  .filter(x => x % 2 === 0)
  .map(x => x ** 2)
  .find(x => x % 3 === 0);

console.log(result);

Desired Behavior

Would be awesome if the snippet above would be implementable without more than 1-2 imports and several method renamings.

Who does this impact? Who is this for?

For newcomers from other FP languages like Scala or Haskell.

Describe alternatives you've considered

To add docs page how to import all the core stuff.

@grossbart
Copy link
Collaborator

Here's something I'm using in a prelude.ts file, it would be interesting to hear from others, too. I don't know whether this would be generalizable, as there's a conflict between wanting to keep the names as short as possible, but not interfering with other people's code.

import * as Ar from "fp-ts/lib/Array";
import * as E from "fp-ts/lib/Either";
import * as Eq from "fp-ts/lib/Eq";
import * as Ma from "fp-ts/lib/Map";
import * as An from "fp-ts/lib/NonEmptyArray";
import * as O from "fp-ts/lib/Option";
import * as Ord from "fp-ts/lib/Ord";
import * as R from "fp-ts/lib/Record";
import * as Te from "fp-ts/lib/TaskEither";
import * as io from "io-ts";
import * as nt from "newtype-ts";

export * from "fp-ts/lib/function";
export * from "fp-ts/lib/pipeable";
export { An, Ar, E, Eq, Ma, O, Ord, R, Te, io, nt };

Also, there's fp-ts-ramda, which @giogonzo is experimenting with, that uses fp-ts under the hood but provides the convenient functions from Ramda.

@cyberixae
Copy link
Contributor

I wrote my own prelude package for my current projects. It doesn't contain all of fp-ts and io-ts. Just the main stuff I'm using. Below is an example of how I use the imports in a project.

import * as P from 'maasglobal-prelude-ts';
P.Either    // static type
P.Either    // io-ts codec
P.Either_   // fp-ts utils
P.Either__  // fp-ts type class implementations

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

No branches or pull requests

4 participants