Skip to content

Enables to create copies (similar to lenses) to generated FSharp.Data types (json only for now)

License

Notifications You must be signed in to change notification settings

jkone27/FSharp.Data.Mutator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Enables to create copies (similar to lenses) to generated FSharp.Data types (json only for now), The library now depends both on FSharp.Data and Newtonsoft.Json as dependencies, but can be improved.

A medium article about it.

Usage

#r "nuget:FSharp.Data.Mutator,0.1.0-beta"

open FSharp.Data
open FSharp.Data.Mutator

[<Literal>]
let jsonTest =
    """
    {
        "name":"hey",
        "nested": {
            "another" : "val"
        },
        "items" : [
            { "first" : 1 }
        ] 
    }
    """

type TestJsonProvided = JsonProvider<jsonTest>

TestJsonProvided.GetSample().Change(fun x -> x.Name = "bye")

Or for a chain of calls (more functional-way)

TestJsonProvided.GetSample()
|> Change <@ fun x -> x.Name = "one" @>
|> Change <@ fun x -> x.Nested.Another = "two" @>
|> Change <@ fun x -> x.Items.[0].First = 500 @>

and the output should be

val it : JsonProvider<...>.Root =
  {
  "name": "one",
  "nested": {
    "another": "two"
  },
  "items": [
    {
      "first": 500
    }
  ]
}

Have fun!

About

Enables to create copies (similar to lenses) to generated FSharp.Data types (json only for now)

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages