-
Notifications
You must be signed in to change notification settings - Fork 2
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
Add update
or map
function to ease bounded number manipulation
#1
Comments
Sorry for the delay, I thought I had responded already!
Hi Hugo. That is a good suggestion. If you make a pr with the code you
suggested I will merge it. Call it `map`. And be sure to make a test for it
too.
Thanks! I'm glad you are finding it useful. I wasn't sure if anyone used
this library! (out of curiosity, what is your use case?)
I'll look for your pr :)
…On Tue, Sep 11, 2018, 4:24 AM Hugo Bessa ***@***.***> wrote:
Hey! First of all, great work on elm-bounded-number using it, loving it.
It is very common for having a way to map a value of a data structure.
Most data structures allow it, such as Maybe, Result, Dict, and so on. It
would be great to have an update or map function so that you can more
easily chain bounded number operations.
I have added a function similar to this one to one of the projects I'm
working on:
mapBounded fn bounded =
let
value = Number.Bounded.value bounded
in
Number.Bounded.set (fn value) bounded
This let's me refactor things like this:
-operation : Int -> Int+operation : Bounded Int -> Int
operation =- (*) 20 >> (+) 10+ Number.Bounded.update <| (*) 20 >> (+) 10
It also makes it easier to refactor from Number.Bounded.inc. Such as:
***@***.***
<hugooliveirad/nanotimers@6961719>
I'm not sure if the proper name should be either map or update.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#1>, or mute the
thread
<https://github.com/notifications/unsubscribe-auth/ABva046eK3b7XODu3lqKITqEOwOMQ5Ucks5uZ51QgaJpZM4WjHBs>
.
|
Never feel sorry for delayed replies on open source work 😄 My use case is that I have timers and the amount of seconds left in the timer should never be below 0. I'll work on a PR and send it your way soon. |
Merged
Published to 2.1.0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hey! First of all, great work on
elm-bounded-number
using it, loving it.It is very common for having a way to map a value of a data structure. Most data structures allow it, such as
Maybe
,Result
,Dict
, and so on. It would be great to have anupdate
ormap
function so that you can more easily chain bounded number operations.I have added a function similar to this one to one of the projects I'm working on:
This let's me refactor things like this:
It also makes it easier to refactor from
Number.Bounded.inc
. Such as: https://github.com/hugobessaa/nanotimers/pull/11/commits/696171908045a3d369a25dd0855ec8eccf474e0eI'm not sure if the proper name should be either
map
orupdate
.What do you think about adding this function? I could send a PR.
The text was updated successfully, but these errors were encountered: