-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
66 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
//=----------------------------------------------------------------------------= | ||
// This source file is part of the Ultimathnum open source project. | ||
// | ||
// Copyright (c) 2023 Oscar Byström Ericsson | ||
// Licensed under Apache License, Version 2.0 | ||
// | ||
// See http://www.apache.org/licenses/LICENSE-2.0 for license information. | ||
//=----------------------------------------------------------------------------= | ||
|
||
//*============================================================================* | ||
// MARK: * Interoperable x Yield | ||
//*============================================================================* | ||
|
||
extension Interoperable { | ||
|
||
//=------------------------------------------------------------------------= | ||
// MARK: Transformations | ||
//=------------------------------------------------------------------------= | ||
|
||
/// Yields its `stdlib` representation. | ||
/// | ||
/// - Note: Use the `stdlib()` method to transfer ownership. | ||
/// | ||
@inlinable public var stdlib: Stdlib { | ||
mutating _read { | ||
let stdlib = self.stdlib() | ||
yield stdlib | ||
self = Self(stdlib) | ||
} | ||
|
||
mutating _modify { | ||
var stdlib = self.stdlib() | ||
yield &stdlib | ||
self = Self(stdlib) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
//=----------------------------------------------------------------------------= | ||
// This source file is part of the Ultimathnum open source project. | ||
// | ||
// Copyright (c) 2023 Oscar Byström Ericsson | ||
// Licensed under Apache License, Version 2.0 | ||
// | ||
// See http://www.apache.org/licenses/LICENSE-2.0 for license information. | ||
//=----------------------------------------------------------------------------= | ||
|
||
//*============================================================================* | ||
// MARK: * Interoperable | ||
//*============================================================================* | ||
|
||
/// A type with a standard-library-compatible representation. | ||
public protocol Interoperable { | ||
|
||
/// The standard-library-compatible representation of `Self`. | ||
associatedtype Stdlib | ||
|
||
//=------------------------------------------------------------------------= | ||
// MARK: Initializers | ||
//=------------------------------------------------------------------------= | ||
|
||
/// Reinterprets the given `source` as this type. | ||
@inlinable init(_ source: consuming Stdlib) | ||
|
||
/// Reiinterprets `self` as a standard-library-compatible type. | ||
@inlinable consuming func stdlib() -> Stdlib | ||
} |