Skip to content

Commit

Permalink
[README] Call standard library code with Interoperable (#74).
Browse files Browse the repository at this point in the history
  • Loading branch information
oscbyspro committed Aug 26, 2024
1 parent e8f7944 commit 5320c23
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 6 deletions.
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
- [Generic logic gates with BitOperable](#corekit-bitwise-logic)
- [Three-way comparisons return Signum](#corekit-signum)
- [Division by multiplication with Divider\<Value\>](#corekit-divider)
- [Call standard library code with Interoperable](#corekit-interoperable)
* [DoubleIntKit](#doubleintkit)
- [A big systems integer](#doubleintkit-systems-integer)
- [A non-recursive model](#doubleintkit-non-recursive-model)
Expand Down Expand Up @@ -476,6 +477,21 @@ You know how the compiler sometimes replaces division with multiplication?
Well, now you can be a wizard too! Divider\<Value\> finds same-size magic
constants and replaces division with: multiplication, addition, and shifts.

<a name="corekit-interoperable"/>

#### Call standard library code with Interoperable

Types conforming to Interoperable have a standard-library-compatible representation,
which is determined by their associated Stdlib type. I32 yields Int32 and U64 yields UInt64,
for example. Interoperable requires bidirectional consuming conversions: *init(\_:)*
and *stdlib()*. It then derives mutating read and modify accessors available through
*stdlib*. You may use these operations to call standard library code, as seen below:

```swift
var randomness = RandomInt() // from RandomIntKit
let random = Bool.random(using: &randomness.stdlib)
```

<a name="doubleintkit"/>

## DoubleIntKit
Expand Down
2 changes: 1 addition & 1 deletion Sources/CoreKit/Interoperable+Yield.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ extension Interoperable {
// MARK: Transformations
//=------------------------------------------------------------------------=

/// Yields its `stdlib` representation.
/// Yields a standard-library-compatible representation.
///
/// - Note: Use the `stdlib()` method to transfer ownership.
///
Expand Down
4 changes: 2 additions & 2 deletions Sources/CoreKit/Interoperable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
/// A type with a standard-library-compatible representation.
public protocol Interoperable {

/// The standard-library-compatible representation of `Self`.
/// A standard-library-compatible representation of `Self`.
associatedtype Stdlib

//=------------------------------------------------------------------------=
Expand All @@ -24,6 +24,6 @@ public protocol Interoperable {
/// Reinterprets the given `source` as this type.
@inlinable init(_ source: consuming Stdlib)

/// Reiinterprets `self` as a standard-library-compatible type.
/// Reinterprets `self` as a standard-library-compatible type.
@inlinable consuming func stdlib() -> Stdlib
}
4 changes: 1 addition & 3 deletions Sources/RandomIntKit/FuzzerInt.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,9 @@ import CoreKit

/// A deterministic source of random data.
///
/// - Important: This model is most suitable for fuzzing.
///
/// ### Algorithm
///
/// It uses `SplitMix64` because it's simple and light-weight.
/// It adapts `SplitMix64` because it's simple and light-weight.
///
/// - Important: It may use a different algorithm in the future.
///
Expand Down

0 comments on commit 5320c23

Please sign in to comment.