-
Notifications
You must be signed in to change notification settings - Fork 5
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
15 changed files
with
344 additions
and
283 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,57 @@ | ||
import Foundation | ||
|
||
|
||
|
||
extension Diffable { | ||
static func diff (between a: Diffable, and b: Diffable) -> Differentia { | ||
guard a != b else { | ||
return Differentia(units: [.notChanged(a)]) | ||
} | ||
|
||
switch (a, b) { | ||
case let (.array(l), .array(r)): | ||
return DiffableSequence.diff( | ||
between: DiffableSequence(l), | ||
and: DiffableSequence(r) | ||
) | ||
|
||
case let (.set(l), .set(r)): | ||
return DiffableSet.diff( | ||
between: DiffableSet(l), | ||
and: DiffableSet(r) | ||
) | ||
|
||
case let (.dictionary(l), .dictionary(r)): | ||
return DiffableDictionary.diff( | ||
between: DiffableDictionary.from(diffableTuples: l), | ||
and: DiffableDictionary.from(diffableTuples: r), | ||
forKind: .dictionary | ||
) | ||
|
||
case let (.anyStruct(type: lt, entries: ld), .anyStruct(type: rt, entries: rd)): | ||
guard lt == rt else { | ||
return Differentia(units: [.deleted(a), .inserted(b)]) | ||
} | ||
|
||
return DiffableDictionary.diff( | ||
between: DiffableDictionary(ld), | ||
and: DiffableDictionary(rd), | ||
forKind: .anyStruct(type: lt) | ||
) | ||
|
||
case let (.anyClass(type: lt, entries: ld), .anyClass(type: rt, entries: rd)): | ||
guard lt == rt else { | ||
return Differentia(units: [.deleted(a), .inserted(b)]) | ||
} | ||
|
||
return DiffableDictionary.diff( | ||
between: DiffableDictionary(ld), | ||
and: DiffableDictionary(rd), | ||
forKind: .anyClass(type: lt) | ||
) | ||
|
||
default: | ||
return Differentia(units: [.deleted(a), .inserted(b)]) | ||
} | ||
} | ||
} |
File renamed without changes.
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
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
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
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,10 @@ | ||
import Foundation | ||
|
||
|
||
|
||
extension Differentia: PrettyPrintable { | ||
var prettyLines: [PrettyLine] { | ||
return self.units | ||
.flatMap { unit -> [PrettyLine] in unit.prettyLines } | ||
} | ||
} |
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,15 @@ | ||
import Foundation | ||
|
||
|
||
|
||
struct Differentia { | ||
let units: [DifferentiaUnit] | ||
} | ||
|
||
|
||
|
||
extension Differentia: Equatable { | ||
static func == (_ lhs: Differentia, _ rhs: Differentia) -> Bool { | ||
return lhs.units == rhs.units | ||
} | ||
} |
Oops, something went wrong.