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

"Point" style coding with fp-ts #14

Open
ChuckJonas opened this issue Mar 30, 2021 · 4 comments
Open

"Point" style coding with fp-ts #14

ChuckJonas opened this issue Mar 30, 2021 · 4 comments

Comments

@ChuckJonas
Copy link
Owner

Starting with CH08, the book often introduces concepts in the "point" style:

Maybe.of(add).ap(Maybe.of(2)).ap(Maybe.of(3));
// Maybe(5)

Task.of(add).ap(Task.of(2)).ap(Task.of(3));
// Task(5)

AFAIK, fp-ts doesn't really provide the ability to use functors in this way (maybe I'm wrong)?

It would be good to add a note on this, along side an example translation.

@ChuckJonas ChuckJonas mentioned this issue Mar 30, 2021
22 tasks
@cdimitroulas
Copy link
Contributor

AFAIK, fp-ts doesn't really provide the ability to use functors in this way (maybe I'm wrong)?

That's correct. It actually used to support this chainable style but it moved to the pipe with fp-ts version 2.0. You can read more about it in this issue if you're curious gcanti/fp-ts#823 (warning: it's a super long discussion 😂)

@ChuckJonas
Copy link
Owner Author

nice, maybe we add a note and just link the issue for anyone who is interested 👍

@ChuckJonas
Copy link
Owner Author

Is there an equaivent type to the container:

// (a -> b) -> Container a -> Container b
Container.prototype.map = function (f) {
  return Container.of(f(this.$value));
};

Container.of(2).map(two => two + 2); 
// Container(4)

Container.of('flamethrowers').map(s => s.toUpperCase()); 
// Container('FLAMETHROWERS')

Container.of('bombs').map(append(' away')).map(prop('length')); 
// Container(10)

I'm guessing not as it only really makes sense if you are chaining/mapping in the point style

@cdimitroulas
Copy link
Contributor

The Identity functor/monad could be similar to Container - https://gcanti.github.io/fp-ts/modules/Identity.ts.html

Not sure if that's more confusing than helpful though

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

2 participants