Comments (7)
"jfieldRepeated" repeated is protobuf terminology and will be confusing in fleece context.
from fleece.
I was analyzing this and came up to with an easy way to have this functionality, with the existing combinators.
Let's pretend we have a pair of functions to go from/to an option of list / plain list:
let flatten = function None -> [] | Some x -> x
let expand = function [] -> None | x -> Some x
Now, we can use them this way:
type Repeat = { Name : string ; Ids : int list } with
static member JsonObjCodec =
fun n i -> { Name = n; Ids = flatten i }
<!> jreq "name" (fun x -> Some x.Name)
<*> jopt "ids" (fun x -> expand x.Ids)
And we'll get the desired effect.
This has the additional advantage that we can apply this to any collection, not just lists and arrays.
from fleece.
My vote would be for jfieldMany
or jfieldRepeated
, is there anyway to work around this with the current combinators?
from fleece.
In Falanx this would be slightly different as it would be a ResizeArray instead
from fleece.
Yes, maybe something like this;
let flatten = function None -> ResizeArray () | Some x -> x
let expand (x: ResizeArray<_>) = if Seq.isEmpty x then None else Some x
from fleece.
Probably this as we would want 0 length intact.
let flattenResizeArray = function None -> ResizeArray() | Some x -> x
let expandResizeArray = function null -> None | x -> Some x
from fleece.
Closing this as a mechanism was suggested in the comments and additionally:
Or maybe we can upgrade the existing jfieldOpt to handle multiple values.
jopt
now as of 0.10.0 supports any type that has defined the zero
value, including lists and arrays, which would do exactly what the title of the issue describes.
from fleece.
Related Issues (20)
- Add FSharPlus.Data types HOT 2
- Documenting different ways to encode DUs HOT 6
- Make it easier to compose ConcreteCodecs HOT 5
- Opposite of Codec.invmap would be useful HOT 1
- Add FSharp.Data Tests and Documentation to work with JSonValue HOT 1
- Compute Field in jsonObjCodec based on another field HOT 5
- question: how to write the type constraints in a generic type? HOT 2
- Add new case of DecodeError which includes an innercase
- Add overloads for UoMized types
- Move benchmarks projects into test folder
- _jkey for undefined or missing value should return None not Some
- Operator `<|>` logic looks wrong, why would I need to use both codes for encoding HOT 3
- Is it possible to make codecs to automatically handle units of measure? HOT 9
- How to encode an enum-style discriminated union
- What if my encoder/decoder/codec depends on some configuration options, am I forced to manually wire up? HOT 1
- Feature request, add parameters for conditional ser/de HOT 3
- Add overload for KeyValuePair HOT 1
- Build on Linux Requires Mono; Sort out What to Do About That
- Proposal/Quesion: add `paket` to docs, use fsx paket extension HOT 4
- Ease way to add JsonObjCodec for types with string transformations HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from fleece.