evilsoft / evilsoft/crocks

Add the StateT monad

Open
#544 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
1.6k
Forks
103
PR merge metrics
No merged PRs in 30d

Description

**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

```javascript
// 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`

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.