JuliaPhysics / JuliaPhysics/Unitful.jl
Extract unit to apply to new value
- Dominant language
- Julia
- Stars
- 675
- Forks
- 124
- Avg merge
- 3h 38m
- Merged PRs (30d)
- 1
Description
Could there be a simpler way to obtain a constructor of the same unit as another value.
For example,
```
get_unit(3u"mg/hr")(3.5) == 3.5u"mg/hr"
```
Something like,
```
using Unitful, Distributions
apply_unit(obj::Real, val::Real) = val
apply_unit(obj::Quantity{<:Any,D,U}, val::T) where {T,D,U} = Quantity{T,D,U}(val)
magic(obj) = apply_unit(obj, mean(rand(Normal(ustrip(obj)), 100)))
```
Contributor guide
No contributing guide indexed for this repository
Research direction
No file or test is named. Start by inspecting the existing Quantity and unit-extraction APIs, along with the proposed get_unit and apply_unit entry points; done would be a supported way to construct a new value with the same unit as an existing value, matching the example.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- julia
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 30/100