Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Prefix partial function names with `unsafe` #42
Folktale has a few functions that are partial (i.e.: not defined for all possible inputs of the types it expects), and when you invoke these functions for an undefined input and exception is thrown. Right now, these functions are not marked in any special way, so code looks like this:
someMaybe.get(); // might throw an exception
In order to make it clear that there might be a problem there, we could use some naming convention. I'm proposing prefixing these functions with
someMaybe.unsafeGet(); // might throw an exception
This would also encourage total functions to be used by default. In the case of
someMaybe.unsafeGet(); // might throw an exception someMaybe.getOrElse(null); // always works
JS does not care much about partiality (many partial functions are provided in the standard library, that either throw an exception or result in nonsensical values), but partiality makes code harder to reason about because the cases where something may fail are not clear from reading just the source code — you also have to read the definitions that you're using, and maybe some external documentation!
Because Folktale aims to provide a better standard library, more aligned with functional programming practices, it would be nice if partiality was thoroughly discouraged. Folktale already discourages partiality in many cases, but there are functions that, historically, have been provided as convenience (such as
While Folktale 2 is a major release, we're trying to keep at least the APIs on the data structures the same as that of Folktale 1, to make it easier for people transitioning from 1 to 2. During this period we'd have the new
Because this is mostly just a naming change, it doesn't affect any other part of the Folktale library itself.
Currently we have the following partial functions:
Is there anything I've missed or any consideration one'd want to add? Is anyone opposed to this direction?