Skip to content

Add getPropOrError to crocks #509

Open
@kierans

Description

@kierans

Is your feature request related to a problem? Please describe.
I'm on my fourth project using Crocks and I keep reaching for the same function getPropOrError (and getPathOrError). Instead of me releasing my own library, or copy/pasting the function around I think it would be good to have this in the standard library.

Describe the solution you'd like
getPropOrError :: String -> a -> Result Error b
getPathOrError :: [ String ] -> a -> Result Error b

Describe alternatives for how you do this now
Doing a maybeToResult on getProp with an Error if getProp returns a Nothing.

Code
Do you have example code or tests in a Repl for what you'd like added?

// getPropOrError :: String -> a -> Result Error b
const getPropOrError = curry((prop, obj) =>
  maybeToResult(new Error(`'${prop}' is mandatory and missing`), getProp(prop, obj))
);

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions