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 the StateT monad #544

Open
kierans opened this issue Apr 27, 2023 · 0 comments
Open

Add the StateT monad #544

kierans opened this issue Apr 27, 2023 · 0 comments

Comments

@kierans
Copy link

kierans commented Apr 27, 2023

Is your feature request related to a problem? Please describe.

Much like with Reader when using the State monad with an inner monad when mapping, or chaining the code gets messy dealing with the inner monad

Describe the solution you'd like
A description of what you'd like to have added to the project.

Like how there's a ReaderT in Crocks, there should be a StateT.

Describe alternatives for how you do this now

Just have to remember to handle the inner monad

// exclaim :: String -> String
const exclaim = concat("!!!")

// toUpper :: String -> String
const toUpper = (s) => s.toUpperCase()

// getName :: Object -> Maybe a
const getName = getProp("name")

// convertName :: String -> String
const convertName = compose(exclaim, toUpper);

// findName :: State Object (Maybe String)
const findName =
  State.get(getName).map(map(convertName))

findName.evalWith({ name: "evilsoft" }).toString()
//=> Just "EVILSOFT!!!"

findName.evalWith({})
//=> Nothing

Code

Additional context
Add any other context or screenshots about the feature request here.

@evilsoft mentioned in one of his YouTube videos that he was planning on writing StateT

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

1 participant