Skip to content

Commit f7dc0d5

Browse files
committed
Make graph expressible by dictionary- and array literals
1 parent df27c68 commit f7dc0d5

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

Code/Graph+CreateAndAccess/Graph+ConvenientInitializers.swift

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,27 @@
1+
//extension Graph: ExpressibleByArrayLiteral where NodeValue: Identifiable, NodeValue.ID == NodeID
2+
//{
3+
// public init(arrayLiteral elements: NodeValue...)
4+
// {
5+
// self.init(values: elements)
6+
// }
7+
//}
8+
9+
extension Graph: ExpressibleByArrayLiteral where NodeID == NodeValue
10+
{
11+
public init(arrayLiteral elements: NodeValue...)
12+
{
13+
self.init(values: elements)
14+
}
15+
}
16+
17+
extension Graph: ExpressibleByDictionaryLiteral
18+
{
19+
public init(dictionaryLiteral elements: (NodeID, NodeValue)...)
20+
{
21+
self.init(idValuePairs: elements)
22+
}
23+
}
24+
125
public extension Graph
226
{
327
init(values: some Sequence<NodeValue>)

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ SwiftNodes is already being used in production, but [Codeface](https://codeface.
221221
## Roadmap
222222

223223
1. Further align API with official Swift data structures (What would Apple do?):
224-
1. Add the usual suspects of applicable protocol conformances (`Sequence`/`Collection`, expressibility by literals, etc.)
224+
1. Add the usual suspects of applicable protocol conformances (`Sequence`/`Collection`)
225225
2. Compare with- and learn from API and implementation of [Swift Collections](https://github.com/apple/swift-collections)
226226
2. Round out and add algorithms (starting with the needs of Codeface):
227227
1. Make existing algorithms compatible with cyclic graphs (two of them are still not)

0 commit comments

Comments
 (0)