Skip to content

v0.3.0

Compare
Choose a tag to compare
@Tarmil Tarmil released this 08 Feb 14:00
· 8 commits to main since this release

Add static classes CustomDiffer and CustomDiffer<T> with facilities for creating ICustomDiffers that add support for specific types.

  • CustomDiffer<T>.Build() creates a custom differ for type T based on a diff function that takes two Ts as argument, and optionally an IDifferFactory that can be used to get differs for nested types.

    type MyRecord = { X: string; Y: string }
    
    /// A differ for `MyRecord` that only looks at `X`.
    let myRecordDiffer = CustomDiffer<MyRecord>.Build(fun differFactory ->
        let stringDiffer = differFactory.GetDiffer<string>()
        fun value1 value2 ->
            stringDiffer.Diff(value1.X, value2.X)
    )
  • CustomDiffer<T>.Map<U>() creates a custom differ for type T by mapping it to a diffable type U.

    type MyOtherRecord = { X: string; Y: string; Z: string }
    
    /// A differ for `MyOtherRecord` that only looks at `X` and `Y`.
    let myOtherRecordDiffer = CustomDiffer<MyRecord>.Map(fun value ->
        {| X = value.X; Y = value.Y |})
  • CustomDiffer.Leaf<T>() creates a custom differ for type T that treats it as a leaf value using standard equality, customizing the string output.

    type Username = Username of string
    
    /// A differ that treats `Username` as if it was directly an unwrapped string.
    let usernameDiffer = CustomDiffer.Leaf(fun (Username x) -> x)
  • CustomDiffer.Combine() creates a custom differ for multiple types by combining multiple custom differs.

    let myDiffer = CustomDiffer.Combine [ myRecordDiffer; myOtherRecordDiffer; usernameDiffer ]