8000 Add the StateT monad · Issue #544 · evilsoft/crocks · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
Add the StateT monad #544
Open
Open
@kierans

Description

@kierans

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0