GitHub - Flight-School/Rate: A type-safe ratio of Foundation unit quantities.
source link: https://github.com/Flight-School/Rate
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
README.md
Rate
A ratio of two related quantities, expressed in terms of an amount of numerator unit per single denominator unit.
This functionality is discussed in Chapter 5 of Flight School Guide to Swift Numbers.
Requirements
- Swift 4.0+
Installation
Swift Package Manager
Add the Rate package to your target dependencies in Package.swift
:
import PackageDescription let package = Package( name: "YourProject", dependencies: [ .package( url: "https://github.com/Flight-School/Rate", from: "1.0.0" ), ] )
Then run the swift build
command to build your project.
Carthage
To use Rate in your Xcode project using Carthage,
specify it in Cartfile
:
github "Flight-School/Rate" ~> 1.0.0
Then run the carthage update
command to build the framework,
and drag the built Rate.framework into your Xcode project.
Usage
One of the shortcomings of the Foundation Unit and Measurement APIs is the inability to dynamically declare compound units. This can make it difficult to perform dimensional analysis and other multi-step calculations.
The Rate
structure allows you to express the ratio
between two units in a type-safe manner.
Multiplying a measurement with one unit type by a rate
whose denominator is that same unit type causes those types to cancel out,
resulting in a measurement with the numerator type.
For example, volume over time multiplied by time yields volume:
let flowRate = Rate<UnitVolume, UnitDuration>(value: 84760, unit: .cubicFeet, per: .seconds) let oneDay = Measurement<UnitDuration>(value: 24, unit: .hours) (flowRate * oneDay).converted(to: .megaliters) // 207371ML
License
MIT
Contact
Mattt (@mattt)
Recommend
-
85
README.md AppleiTunesSearchURLComponents Router for the iTunes Search API. T...
-
34
If you’re developing software that operates a lot with physical quantities you absolutely should use a library that defines types for quantities and supports safe conversions between units of measurements. Our go-to librar...
-
4
On the gender ratio at Startup School and tech in general There's an "ask Hacker News" post from last night which basically asks why there were so few women at Startup Scho...
-
21
Make line item quantities adjustableConfigure the Checkout Session so customers can adjust line item quantity during checkout.Only Checkout payment mode is su...
-
1
News Lambda School 2020 Placement Rate at 30%: Insider Report Leaked documents reveal rapidly declining placement rates at Lambda School....
-
5
Ransomware Has Disrupted Almost 1,000 Schools in the US This YearThere have been more than 70 ransomware attacks affecting around 1,000 U.S. schools this year, and it may get worse before it gets better.
-
10
ABAP CDS Cheat Sheet: Amounts and Quantities in ABAP CDS 1 3 179 In ABAP CDS, a special handli...
-
4
Samsung releases 3nm chips in very limited quantities
-
0
US agencies buy vast quantities of personal information on the open market—what it means for privacy in the age of AI by Anne Toomey McKenna,...
-
2
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK