-
Notifications
You must be signed in to change notification settings - Fork 30
add Int.clamp and Float.clamp #90
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
Conversation
I like these and I reach for similar functionality here and there. So I'm in favor of including it. @cknitt, thoughts? |
Personally I have not missed those yet, but I am not against adding them. |
I think there is something a little random about adding this function and not dealing with max, min, and others. See the static methods on the .net Int. But there is max, min, minMagnitude, isOdd, isEven, etc. https://learn.microsoft.com/en-us/dotnet/api/system.int32?view=net-7.0#methods Rust... https://doc.rust-lang.org/std/primitive.i32.html And when should something go in the |
What's random about it? It fixes a specific problem with the existing functions while preserving the originals, since it's an objective of this project to stick close to JS APIs for familiarity. |
Is this in JavaScript already and JS developers expect it? I couldn't find it. I'm not understanding where this is coming from. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number |
It doesn't exist in JS, no, and the rationale is in the OP. I'm not sure what you're asking for beyond that. |
I agree this is a useful thing and I'd be happy to see it in the library. I want the end result of this project to be a library that feels cohesive, well-thought-through, consistent. Good consistent naming, like |
I think this is the wrong place to have that discussion, and I also think that you've had it answered at least partly elsewhere. That a major focus of this library is familiarity with JS, not cohesiveness, and JS APIs unfortunately aren't very cohesive. It's still not a bad question, but I don't think it's a good idea to have the discussion scattered across multiple threads and to derail other issues and PRs with tangentially related questions. |
I'm not sure where to have a discussion. I posted a couple high-level questions on Issues - "should we fill out the option module?" and "what is the process for deciding what gets in?" - and got no response. There's no Discussions tab in this repo. You and everyone else on this project probably have a long history and know exactly what's going on. And I'm barging in asking annoying questions and providing opinions no one wants to hear. I like ReScript and want to help. I think I could contribute to the Option and Result modules if it is a goal to make those better. I will look at the "help wanted" issues and see if there is anything I can do there. |
I wouldn't say you got no responses on the high-level issue you created for the Options module. I do get a sense that what you're asking for is mostly out-of-scope though, but it would be good to have more clarity on what is in and out of scope. I'm not too sure either where to have these discussions, there is for example a rescript forum too, but it's certainly better to have high-level discussions in high-level issues than scattered across tangentially related PRs. As for contributions, what's been actively asked for is mostly just documentation for what already exists. I think that would be a great place to start to get a sense of things as they are. |
@glennsl mind rebasing this one as well? Ready to merge after. |
And done. |
I always find using
min
andmax
functions quite awkward, since piping them sort of inverts their meaning3->max(2) == 3
and not piping them is sometimes awkward in itself if part of a larger pipeline, and especially if both are used togethermin(3, max(2, 1)) == ??
.clamp
fixes all of these problems.