Skip to content

Commit

Permalink
Expose _CurrencyImplementation as CurrencyProtocol
Browse files Browse the repository at this point in the history
Motivation:

Working with currencies in generic cases aren't always practical with the type-erased `AnyCurrency` protocol, as repeated type constraints are added to access `Comparable` and `Hashable` conformances.

The `_CurrencyImplementation` doesn't need to be private, as anyone could conform to the protocol to gain much of the flexibility of `AnyCurrency` while also working in hashing contexts such as `Set`.

Modifications:

- Rename `_CurrencyImplementation` to `CurrencyProtocol` and make public
- Remove `CurrencyMetadata` superset requirements from `CurrencyProtocol`

Result:

Developers should have more flexibility with the Currency module types to work in existential or generic contexts
  • Loading branch information
Mordil committed Jan 21, 2020
1 parent 3519d29 commit d4fcba8
Show file tree
Hide file tree
Showing 4 changed files with 347 additions and 340 deletions.
25 changes: 25 additions & 0 deletions Sources/Currency/CurrencyProtocol.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
//===----------------------------------------------------------------------===//
//
// This source file is part of the Currency open source project
//
// Copyright (c) 2020 Currency project authors
// Licensed under MIT License
//
// See LICENSE.txt for license information
// See CONTRIBUTORS.txt for the list of Currency project authors
//
// SPDX-License-Identifier: MIT
//
//===----------------------------------------------------------------------===//

/// Represents a type that acts as a currency.
///
/// Any `CurrencyProtocol` type behaves exactly like an `AnyCurrency` type, while also providing other capabilities such as
/// `Comparable`, `Hashable`, etc.
///
/// This is the type to work with in most generic cases, as `AnyCurrency` is a type-erasure protocol when existentials are needed.
public protocol CurrencyProtocol: AnyCurrency,
Comparable, Hashable,
ExpressibleByIntegerLiteral, ExpressibleByFloatLiteral,
AdditiveArithmetic
{ }
Loading

0 comments on commit d4fcba8

Please sign in to comment.