JuliaPhysics / JuliaPhysics/Unitful.jl

quantity(FloatType, unit) function

Open
#385 0 comments 1 reaction 0 assignees View on GitHub
Dominant language
Julia
Stars
675
Forks
124
Avg merge
3h 38m
Merged PRs (30d)
1

Description

Declaring a Unitful unit in a struct could be made nicer, if the following function **quantity(..)** is provided in Unitful:

```
using Unitful

# The following function should be defined inside Unitful
quantity(FloatType, unit) = Quantity{FloatType, dimension(unit), typeof(unit)}

mutable struct Data{FloatType <: AbstractFloat}
length::quantity(FloatType, u"m")
end

L = Data{Float64}(2.0u"mm")
@show L
```

Of course, it is easy to introduce such a function in an own package. However, it would be better if this feature is directly provided by Unitful.

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by reading Unitful's existing quantity and unit type definitions, then compare them with the proposed Julia example. The work is done when Unitful provides the requested quantity(FloatType, unit) form and the shown Data struct can declare and construct its length field as demonstrated.

Written by the indexing model from the issue text.

Assessment

Tech stack
julia
Domain
backend
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.