Skip to content

Commit cc2df5a

Browse files
authored
Add Map API (#123)
* Add Map and update folder structure * Add Map test case * Update dependency
1 parent fed9335 commit cc2df5a

File tree

16 files changed

+67
-43
lines changed

16 files changed

+67
-43
lines changed

Package.resolved

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Sources/OpenGraph/Attribute/Attribute/External.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ public struct External<Value> {
1414

1515
extension External: _AttributeBody {
1616
public static var comparisonMode: OGComparisonMode { ._3 }
17+
1718
public static var flags: OGAttributeTypeFlags { [] }
19+
1820
public static func _update(_: UnsafeMutableRawPointer, attribute _: AnyAttribute) {}
1921
}
2022

Sources/OpenGraph/Attribute/Attribute/Focus.swift renamed to Sources/OpenGraph/Attribute/Rule/Focus.swift

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,19 @@
55
// Audited for RELEASE_2021
66
// Status: Complete
77

8-
public struct Focus<Root, Value> {
8+
@frozen
9+
public struct Focus<Root, Value>: Rule, CustomStringConvertible {
910
public var root: Attribute<Root>
1011
public var keyPath: KeyPath<Root, Value>
1112

1213
public init(root: Attribute<Root>, keyPath: KeyPath<Root, Value>) {
1314
self.root = root
1415
self.keyPath = keyPath
1516
}
16-
}
17-
18-
// MARK: - Rule
1917

20-
extension Focus: Rule {
2118
public var value: Value { root.value[keyPath: keyPath] }
22-
public static var flags: OGAttributeTypeFlags { [] }
23-
}
2419

25-
// MARK: CustomStringConvertible
20+
public static var flags: OGAttributeTypeFlags { [] }
2621

27-
extension Focus: CustomStringConvertible {
2822
public var description: String { "\(Metadata(Value.self).description)" }
2923
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
//
2+
// Map.swift
3+
// OpenGraph
4+
//
5+
// Audited for RELEASE_2021
6+
// Status: Complete
7+
8+
// MARK: - Map
9+
10+
@frozen
11+
public struct Map<Source, Value>: Rule, CustomStringConvertible {
12+
public var arg: Attribute<Source>
13+
public let body: (Source) -> Value
14+
15+
public init(_ arg: Attribute<Source>, _ body: @escaping (Source) -> Value) {
16+
self.arg = arg
17+
self.body = body
18+
}
19+
20+
public var value: Value { body(arg.value) }
21+
22+
public static var flags: OGAttributeTypeFlags { [] }
23+
24+
public var description: String { "λ \(Value.self)" }
25+
}

Sources/OpenGraph/Attribute/Rule/AnyRuleContext.swift renamed to Sources/OpenGraph/Attribute/RuleContext/AnyRuleContext.swift

File renamed without changes.

Sources/OpenGraph/Attribute/Rule/RuleContext.swift renamed to Sources/OpenGraph/Attribute/RuleContext/RuleContext.swift

File renamed without changes.

Tests/OpenGraphCompatibilityTests/Attribute/Attribute/AttributeTests.swift

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
//
22
// AttributeTests.swift
3-
//
4-
//
5-
//
3+
// OpenGraphCompatibilityTests
64

75
import Testing
86

Tests/OpenGraphCompatibilityTests/Attribute/Attribute/ExternalTests.swift

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
//
22
// ExternalTests.swift
3-
//
4-
//
5-
//
3+
// OpenGraphCompatibilityTests
64

75
import Testing
86

Tests/OpenGraphCompatibilityTests/Attribute/Attribute/FocusTests.swift

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
//
22
// FocusTests.swift
3-
//
4-
//
5-
//
3+
// OpenGraphCompatibilityTests
64

75
import Testing
86

Tests/OpenGraphCompatibilityTests/Attribute/Indirect/IndirectAttributeTests.swift

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
//
22
// IndirectAttributeTests.swift
3-
//
4-
//
5-
// Created by Kyle on 2024/3/3.
6-
//
3+
// OpenGraphCompatibilityTests
74

85
import Testing
96

0 commit comments

Comments
 (0)