enum-fp icon indicating copy to clipboard operation
enum-fp copied to clipboard

Needs use cases and more examples

Open phenax opened this issue 6 years ago • 3 comments

phenax avatar Oct 12 '18 16:10 phenax

I've been trying to work through some of the examples with limited success. For example https://github.com/phenax/enum-fp#pattern-matching works fine,

However https://github.com/phenax/enum-fp#safely-work-with-emptyinvalid-states doesn't include getUser() and I don't know what it is expected to return.

Other examples like: https://github.com/phenax/enum-fp#in-the-functional-world do not show how to actually use them.

I also tried https://gist.github.com/phenax/e841e54a2826c1d52b6dce3c493ef792#file-maybe-js from the Medium article https://medium.com/@phenax5/writing-cleaner-and-safer-javascript-with-sum-types-bec9c68ba7aa and it fails because user is not defined anywhere in Maybe.match(getFirstName(user) and I also assume that isUserValid() is missing.

For folks with a good understanding of FP some of this may not be such a problem, but for someone like me who is very new to FP I have very little understanding of many of the concepts included with enum-fp and more concrete executable examples along with more documentation would help greatly.

I have no doubt enum-fp provides some really useful tools to help with our Javascript development but this mostly alludes me right now.

nevf avatar Apr 01 '19 07:04 nevf

@nevf. Thank you for bringing up theses issues. In retrospect, I feel like I may have posted the example with a tunnel vision perspective towards functional programming.

  1. The getUser was just a function that returns a user object. I'll update the example to get rid of that to make things clearer.
  2. I'll add a description and some references to the Maybe and Either monads so everyone has a reference for how it works.
  3. user is a normal object with the firstName property. I'll define user in the example so that it is clearer.

phenax avatar Apr 01 '19 07:04 phenax

@phenax Many thanks, I look forward to the updates and trying the examples again.

nevf avatar Apr 01 '19 07:04 nevf