Mutualise `encodeArray`, `encodeList`, `encodeSeq`
Closed this issue · 4 comments
In the encoder helpers we have several ways to encode a "sequence" of items.
Thoth.Json/packages/Thoth.Json.Core/Types.fs
Lines 29 to 31 in 4f34bac
Should we remove all of them except one ?
I suppose the only reason for keeping them separate would be to avoid a transformation phase when supported by the JSON backend. Would mapping them have a lot of impact on performance?
For example, Newtonsoft backend is implemented has which means we pass the "sequence" as is:
Thoth.Json/packages/Thoth.Json.Newtonsoft/Encode.fs
Lines 27 to 29 in 4f34bac
For other backend we do a mapping:
Thoth.Json/packages/Thoth.Json.Python/Encode.fs
Lines 27 to 33 in 4f34bac
@njlr What do you think about keeping only one of the member? If we keep only one which one should we keep?
I know that some people say that F# libraries should expose seq
should it be this one? Or does it have a performance cost and we should favour ResizeArray
or array
?
I think it's better to have several functions.
- There are potential performance benefits that some back-ends may utilize
- Some F# users like to specify types in their by using specialized functions
e.g.
let foo xs =
xs
|> Array.map (fun x -> x + 1) // Makes xs an array
- There are potential performance benefits that some back-ends may utilize
Agree
2. Some F# users like to specify types in their by using specialized functions
I don't understand the relation as helpers
are internal APIs.
But we will keep the separate APIs, does this means we should add a new one for ResizeArray
too ? 🤔
I don't understand the relation as
helpers
are internal APIs.
Ah, I was responding to removing Encode.list
, Encode.array
, etc. in favor of just Encode.seq
But we will keep the separate APIs, does this means we should add a new one for ResizeArray too ? 🤔
I think this makes sense to add!
Ah, I was responding to removing
Encode.list
,Encode.array
, etc. in favor of justEncode.seq
Ah yes, no I would still have exposed the different types for the Encode
/Decode
API