Closed amaury1093 closed 5 years ago
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:
get :: (Any -> Boolean) -> String -> a -> Maybe b
gets :: (Any -> Boolean) -> Array String -> a -> Maybe b
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.
This is more a question, for me learning FP. Why are the functions
prop
andprops
throwing an error when the property is not found in the object? This doesn't makeprop
mappable.https://github.com/sanctuary-js/sanctuary/blob/ecde7d4a48e93397d56078ea606ba2c4dcd26541/index.js#L3838-L3845
I would have expected a
Maybe
. fwiw, Ramda returnsa | undefined
.