Sanctuary: Why are `prop` and `props` throwing?

Created on 1 Apr 2019  路  1Comment  路  Source: sanctuary-js/sanctuary

This is more a question, for me learning FP. Why are the functions prop and props throwing an error when the property is not found in the object? This doesn't make prop mappable.

https://github.com/sanctuary-js/sanctuary/blob/ecde7d4a48e93397d56078ea606ba2c4dcd26541/index.js#L3838-L3845

I would have expected a Maybe. fwiw, Ramda returns a | undefined.

Most helpful comment

Hello and welcome, @amaurymartiny !

Conceptually, prop and props only operate on records. These are types like the following:

{ name :: String, dob :: Date }

You could use prop ('name') on this value safely, because it must have a name. And you want it to throw if the name is missing, because that would actually be a bug.

What you might be looking for instead are the following functions:

Conceptually, they operate mainly on string maps and other types whose keys are not known beforehand. They can even be used to operate on types whose values are unknown beforehand, by using the first argument: a predicate to ensure the gotten value conforms to expectations.

>All comments

Hello and welcome, @amaurymartiny !

Conceptually, prop and props only operate on records. These are types like the following:

{ name :: String, dob :: Date }

You could use prop ('name') on this value safely, because it must have a name. And you want it to throw if the name is missing, because that would actually be a bug.

What you might be looking for instead are the following functions:

Conceptually, they operate mainly on string maps and other types whose keys are not known beforehand. They can even be used to operate on types whose values are unknown beforehand, by using the first argument: a predicate to ensure the gotten value conforms to expectations.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jmatsushita picture jmatsushita  路  4Comments

davidchambers picture davidchambers  路  8Comments

t1ger-0527 picture t1ger-0527  路  3Comments

andrei-cacio picture andrei-cacio  路  8Comments

blackxored picture blackxored  路  7Comments