Skip to content

Commit

Permalink
Rename to FSharp.UMX
Browse files Browse the repository at this point in the history
  • Loading branch information
alfonsogarciacaro committed Feb 5, 2019
1 parent 3c5e4ac commit 098e36e
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 25 deletions.
5 changes: 3 additions & 2 deletions Build.fsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#load "node_modules/fable-publish-utils/PublishUtils.fs"
open PublishUtils

// run "npm test"
run "dotnet test"

match args with
| IgnoreCase "publish"::_ ->
pushNuget "src/UnitsOfMeasure.Extra.fsproj"
pushNuget "src/FSharp.UMX.fsproj"
| _ -> ()
4 changes: 2 additions & 2 deletions UnitsOfMeasure.Extra.sln → FSharp.UMX.sln
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.26124.0
MinimumVisualStudioVersion = 15.0.26124.0
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "UnitsOfMeasure.Extra", "src\UnitsOfMeasure.Extra.fsproj", "{194B07ED-714F-48CD-A1E3-E09862D58F60}"
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "FSharp.UMX", "src\FSharp.UMX.fsproj", "{194B07ED-714F-48CD-A1E3-E09862D58F60}"
EndProject
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "UnitsOfMeasure.Extra.Tests", "tests\UnitsOfMeasure.Extra.Tests.fsproj", "{431B9BEF-AC69-43FF-8CB8-7900E8E0FB83}"
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "FSharp.UMX.Tests", "tests\FSharp.UMX.Tests.fsproj", "{431B9BEF-AC69-43FF-8CB8-7900E8E0FB83}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# UnitsOfMeasure.Extra
# FSharp.UMX

F# Units of Measure for non-numeric types by Eirik Tsarpalis. Compatible with Fable.

## Installing

Add the `UnitsOfMeasure.Extra` package from Nuget or just copy the `src/UnitsOfMeasure.Extra.fs` file.
Add the `FSharp.UMX` package from Nuget or just copy the `src/FSharp.UMX.fs` file.

## Publishing to Nuget

Expand All @@ -13,7 +13,7 @@ Run `npm i && npm run build publish`.
## Usage

```fsharp
open UnitsOfMeasure.Extra
open FSharp.UMX
[<Measure>] type customerId
[<Measure>] type orderId
Expand All @@ -39,11 +39,11 @@ let printOrder (order : Order) =
let lookupById (orders : Order list) (id : string<orderId>) = orders |> List.tryFind (fun o -> o.id = id)
lookupById [] order.id // compiles
lookupById [] order.customer // compiler error
lookupById [] order.customer // compiler error
// stdin(94,15): error FS0001: Type mismatch. Expecting a
// 'string<orderId>'
// 'string<orderId>'
// but given a
// 'string<customerId>'
// 'string<customerId>'
// The unit of measure 'orderId' does not match the unit of measure 'customerId'
```

Expand Down
8 changes: 4 additions & 4 deletions src/UnitsOfMeasure.Extra.fs → src/FSharp.UMX.fs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace UnitsOfMeasure.Extra
namespace FSharp.UMX

// Units of Measure extensions
// Provides a mechanism for extending units of measure to non-numeric primitives
Expand All @@ -16,14 +16,14 @@ open System
[<MeasureAnnotatedAbbreviation>] type DateTimeOffset<[<Measure>] 'm> = DateTimeOffset

module private Unsafe =
let inline cast<'a, 'b> (a : 'a) : 'b =
let inline cast<'a, 'b> (a : 'a) : 'b =
#if !FABLE_COMPILER
(# "" a : 'b #)
#else
unbox<'b> a
#endif

type UoM =
type UMX =

static member inline tag<[<Measure>]'m> (x : bool) : bool<'m> = Unsafe.cast x
static member inline tag<[<Measure>]'m> (x : int) : int<'m> = Unsafe.cast x
Expand Down Expand Up @@ -70,4 +70,4 @@ module Operators =

// NB the particular infix operator shadows the rarely used quotation splicing operator
/// Infix operator used for tagging, untagging, or casting units of measure
let inline (~%) (x : ^xm) : ^xn = _cast<UoM, ^xm, ^xn> x
let inline (~%) (x : ^xm) : ^xn = _cast<UMX, ^xm, ^xn> x
6 changes: 3 additions & 3 deletions src/UnitsOfMeasure.Extra.fsproj → src/FSharp.UMX.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

<PropertyGroup>
<Version>1.0.0</Version>
<PackageVersion>1.0.0-beta-006</PackageVersion>
<PackageVersion>1.0.0-beta-005</PackageVersion>
<TargetFrameworks>net45;netstandard2.0</TargetFrameworks>
<GenerateDocumentationFile Condition=" '$(Configuration)' == 'Release' ">true</GenerateDocumentationFile>
<WarningLevel>5</WarningLevel>
Expand All @@ -12,7 +12,7 @@
</PropertyGroup>

<ItemGroup>
<Compile Include="UnitsOfMeasure.Extra.fs" />
<Compile Include="FSharp.UMX.fs" />
</ItemGroup>

<ItemGroup>
Expand All @@ -23,4 +23,4 @@
<PackageReference Include="FSharp.Core" Version="3.1.2.5" Condition=" '$(TargetFramework)' == 'net45' " />
<PackageReference Include="FSharp.Core" Version="4.3.4" Condition=" '$(TargetFramework)' == 'netstandard2.0' " />
</ItemGroup>
</Project>
</Project>
12 changes: 6 additions & 6 deletions tests/UnitsOfMeasure.fs → tests/FSharp.UMX.Tests.fs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
module UnitsOfMeasure.Extra.Tests
module FSharp.UMX.Tests

open System
open Xunit
open UnitsOfMeasure.Extra
open FSharp.UMX

[<Measure>] type skuId
[<Measure>] type km
Expand All @@ -19,10 +19,10 @@ type Record =

[<Fact>]
let ``Simple unit of measure conversions``() =
let x = Guid.NewGuid() |> UoM.tag<skuId>
let y = (UoM.untag x).ToString("N") |> UoM.tag<skuId>
let z = UoM.tag<km> 42
let w = sprintf "%O %s %d" (UoM.untag x) (UoM.untag y) z
let x = Guid.NewGuid() |> UMX.tag<skuId>
let y = (UMX.untag x).ToString("N") |> UMX.tag<skuId>
let z = UMX.tag<km> 42
let w = sprintf "%O %s %d" (UMX.untag x) (UMX.untag y) z
()

[<Fact>]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
</PropertyGroup>

<ItemGroup>
<Compile Include="UnitsOfMeasure.fs" />
<Compile Include="FSharp.UMX.Tests.fs" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="../src/UnitsOfMeasure.Extra.fsproj" />
<ProjectReference Include="../src/FSharp.UMX.fsproj" />
</ItemGroup>

<ItemGroup>
Expand Down

0 comments on commit 098e36e

Please sign in to comment.