-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Sample Code Inaccurate #18
Comments
In the sample code, any unmatched string will return The |
It feels hopelessly naive of you two to expect the sample code to actually work. Wake up and smell the coffee. |
I'll update the README shortly, but here's the correct code: const fullName = first(
(t: string) => t === "Bill" ? "Bill Barnes" : undefined,
t => t === "Hao" ? "Hao Luo" : undefined,
t => t === "Kevin" ? "Kevin Leung" : undefined,
); In the real world I'd probably introduce a helper, e.g. const getFullName = (
name: string,
fullName: string
) => (t: string) => t === name ? fullName : undefined;
const fullName = first(
getFullName("Bill", "Bill Barnes"),
getFullName("Hao", "Hao Luo"),
getFullName("Kevin", "Kevin Leung"),
); ... but that probably would make the samples less clear. |
first() documentation
Code (in sample):
Actual:
When "Bill" argument is commented out (line 2), results are:
If a fall through behavior is correct, samples are wrong.
The text was updated successfully, but these errors were encountered: