Dwifft
public struct Dwifft
Namespace for the diff
and apply
functions.
-
Returns the sequence of
DiffStep
s required to transform one array into another.Declaration
Swift
public static func diff<Value: Equatable>(_ lhs: [Value], _ rhs: [Value]) -> [DiffStep<Value>]
Parameters
lhs
an array
rhs
another, uh, array
Return Value
the series of transformations that, when applied to
lhs
, will yieldrhs
. -
Applies a diff to an array. The following should always be true: Given
x: [T], y: [T]
,Dwifft.apply(Dwifft.diff(x, y), toArray: x) == y
Declaration
Swift
public static func apply<Value>(diff: [DiffStep<Value>], toArray lhs: [Value]) -> [Value]
Parameters
diff
a diff, as computed by calling
Dwifft.diff
. Note that you be careful to not modify said diff before applying it, and to only apply it to the left hand side of a previous call toDwifft.diff
. If not, this can (and probably will) trigger an array out of bounds exception.lhs
an array.
Return Value
lhs
, transformed bydiff
. -
Returns the sequence of
SectionedDiffStep
s required to transform oneSectionedValues
into another.Declaration
Swift
public static func diff<Section: Equatable, Value: Equatable>(lhs: SectionedValues<Section, Value>, rhs: SectionedValues<Section, Value>) -> [SectionedDiffStep<Section, Value>]
Parameters
lhs
a
SectionedValues
rhs
another, uh,
SectionedValues
Return Value
the series of transformations that, when applied to
lhs
, will yieldrhs
. -
Applies a diff to a
SectionedValues
. The following should always be true: Givenx: SectionedValues<S,T>, y: SectionedValues<S,T>
,Dwifft.apply(Dwifft.diff(lhs: x, rhs: y), toSectionedValues: x) == y
Declaration
Swift
public static func apply<Section, Value>(diff: [SectionedDiffStep<Section, Value>], toSectionedValues lhs: SectionedValues<Section, Value>) -> SectionedValues<Section, Value>
Parameters
diff
a diff, as computed by calling
Dwifft.diff
. Note that you be careful to not modify said diff before applying it, and to only apply it to the left hand side of a previous call toDwifft.diff
. If not, this can (and probably will) trigger an array out of bounds exception.lhs
a
SectionedValues
.Return Value
lhs
, transformed bydiff
.