-
Notifications
You must be signed in to change notification settings - Fork 71
splitAt without Maybe? #78
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
Comments
I suggest a separate |
So the way I see it there are 3 options:
Option 1 is actually my least favourite. The way I see it, the most important thing is that the API exported by this package is coherent and consistent. I don't think people wanting/needing to define helper functions locally is always a bad thing; in fact I think it often isn't. Given that |
Okay ... that makes sense to me. I lean towards option 2 as well. Is there a compelling use case for |
I'm not able to think of one off the top of my head but perhaps someone else will be able to. |
The current return type preserves more information about the input, avoiding code like this:
Since these functions are not designed to preserve information, |
I guess I'm still not sure what the usefulness of your above hypothetical example is ... But does it impede the working of the function to return a record regardless of indices passed? Could the interest of be equally or better served with a separate function that checks the indices? I mean, currently most code will still have to unwrap from Also, I would like to note that bounds checking for an index does depend on how the index is being used: |
Daniel Spiewak demonstrated problems with this approach in May Your Data Ever Be Coherent. |
Yes I am perfectly aware of the issue presented within the first 4 minutes of that talk. I cringe just about every time I see code like that. But I disagree that Substring returns decent results for any integer passed in. So I think the Does data coherence matter if a function is doing two things? I still don't understand the need for index checking, particularly with Is it to check user input to see if they have entered a valid position? Is it to check code generating indices into Is coherence relevant when the algorithm gives just as good results without the conditional? In fact I would argue that better coherence dictates removing the conditional which has no bearing on the validity of the result, and, as I argue, is incorrect, partially since it was separately derived. Unless you have a nice counterexample, I don't see the utility of index checking within To my eye (I can't say I fully comprehend it), this (one of the few github-searchable examples of using Furthermore, in the other search results for |
My concerns were philosophically rather than practically motivated, @NasalMusician. :) Thank you for making a clear case for |
Resolved in 0.12 branch |
In my project I've had to define a
splitAtTuple
but even after #69 was fixed I still use it because I don't like theMaybe
in the return type: just return an emptyString
on one side!I would prefer it if basically any string index was considered "valid" insofaras it would return a record instead of a
Maybe
, with values ranging between{ before: "", after: s }
and{ before: s, after: "" }
.Based on JavaScript
String.prototype.substring
behavior, it looks like this would amount to just removing the conditional (since substrings with negative indices and indices beyond the end of the string just return the whole string or empty as appropriate).Is this something you are willing to change again, or would it be best to introduce like a
splitAt'
in this library with my suggested version?The text was updated successfully, but these errors were encountered: