fsprojects / Fleece

Json mapper for F#
http://fsprojects.github.io/Fleece
Apache License 2.0
199 stars 31 forks source link

Example from README does not compile #91

Closed wallymathieu closed 2 years ago

wallymathieu commented 4 years ago
open System.Json
open Fleece.SystemJson
open Fleece.SystemJson.Operators

type PersonF = { 
    name : string * string
    age : int option
    children: PersonF list }
    with
    static member JsonObjCodec =
        fun f l a c -> { name = (f, l); age = a; children = c }
        |> withFields
        |> jfield    "firstName" (fun x -> fst x.name)
        |> jfield    "lastName"  (fun x -> snd x.name)
        |> jfieldOpt "age"       (fun x -> x.age)
        |> jfield    "children"  (fun x -> x.children)
wallymathieu commented 4 years ago

Seems like it compiles if I do:

type PersonF = { 
    name : string * string
    age : int option
    children: PersonF list }
    with
    static member JsonObjCodec =
        fun f l a c -> { name = (f, l); age = a; children = c }
        |> withFields
        |> jfield    "firstName" (fun x -> fst x.name)
        |> jfield    "lastName"  (fun x -> snd x.name)
        |> jfieldOpt "age"       (fun x -> x.age)
        |> jfieldWith jsonValueCodec "children"  (fun x -> x.children)
gusty commented 2 years ago

Since changes and additions in 0.10.0 the Readme was completely upgraded.

wallymathieu commented 2 years ago

This example does compile

#r "nuget: Fleece.SystemJson, 0.10.0"
#r "nuget: System.Json, 4.7.1"
open System.Json
open Fleece.SystemJson
open Fleece.SystemJson.Operators

type PersonF = { 
    name : string * string
    age : int option
    children: PersonF list }
    with
    static member JsonObjCodec =
        fun f l a c -> { name = (f, l); age = a; children = c }
        |> withFields
        |> jfield    "firstName" (fun x -> fst x.name)
        |> jfield    "lastName"  (fun x -> snd x.name)
        |> jfieldOpt "age"       (fun x -> x.age)
        |> jfield    "children"  (fun x -> x.children)