Open haf opened 9 years ago
This use case might be solved by the addition of Json.writeWith
and Json.readWith
from #44.
Here's a PropertyWith
, please add?
let inline (|PropertyWith|) fromJson key =
Lens.getPartial (Json.Object_ >??> key_ key)
>> Option.bind (fromJson >> function | Value a, _ -> Some a
| _, _ -> None)
No problem, I'll get that in very soon - useful addition. There's likely to be a new Aether and Chiron (better in some serious ways I hope) out very soon, I'm kind of considering this weekend...
Awesome.
Beware that I've lost the connection with the API changes you've done to Aether (haven't seen any docs either), so I'm currently only using older versions of it.
Yeah new docs do need to be done before a release actually... I think I might branch off the new version bits for Chiron for now and do a point release to get this change in, as it's useful to an actual user.
How are you using Aether at the moment? If a library, then the new changes have backwards compatible aliases until the next major version anyway. The new changes are cool though, reducing the number of operators, better type inference, etc.
On 4 December 2015 at 13:13, Henrik Feldt notifications@github.com wrote:
Awesome.
Beware that I've lost the connection with the API changes you've done to Aether (haven't seen any docs either), so I'm currently only using older versions of it.
— Reply to this email directly or view it on GitHub https://github.com/xyncro/chiron/issues/39#issuecomment-161964130.
Cool. Well if you're usually pulling it in as a library, then it should be fine. And obviously it'll be a new major version, so if you've pinned things also no problem.
I'm thinking of using it like this:
type PointValue =
/// Value at point in time
| Gauge of Value * Units
/// Any sort of derived measure
| Derived of Value * Units
/// All simple-valued fields' values can be templated into the template string
/// when outputting the value in the target.
| Event of template:string
with
static member private valueUnitsToJson (value : Value, units : Units) : Json<unit> =
Json.write "value" value
*> Json.write "units" units
static member private valueUnitsFromJson : Json<Value * Units> =
(fun value units -> value, units)
<!> Json.read "value"
<*> Json.read "units"
static member ToJson (pv : PointValue) : Json<unit> =
let inJsonObject writer =
writer (Json.Object Map.empty) |> snd
match pv with
| Gauge (value, units) ->
Json.writeWith (PointValue.valueUnitsToJson >> inJsonObject) "gauge" (value, units)
| Derived (value, units) ->
Json.writeWith (PointValue.valueUnitsToJson >> inJsonObject) "derived" (value, units)
| Event template ->
Json.write "event" template
That seems pretty sensible.
This has been merged in, and is out in 8.0.0-rc4 - definitely take a look at getting the latest. There's a backwards compat layer, but the new version is nicer when switched!
I often have a tuple in F# 3-5 items long, but want to serialise it as an object; then I need to do lots of shenanigans.
With these I don't:
Means I can have this usage:
What about adding them to the project?