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.
I would have expected a Maybe. fwiw, Ramda returns a | undefined.
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 bgets :: (Any -> Boolean) -> Array String -> a -> Maybe bConceptually, 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.
Most helpful comment
Hello and welcome, @amaurymartiny !
Conceptually,
propandpropsonly operate on records. These are types like the following: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 bgets :: (Any -> Boolean) -> Array String -> a -> Maybe bConceptually, 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.