Skip to content

Commit

Permalink
Add Decode.andMap allowing to decoder large objects incrementally
Browse files Browse the repository at this point in the history
  • Loading branch information
Maxime Mangel committed Nov 9, 2022
1 parent dc831dd commit ec8964b
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* Add doc comment to `Decode.fromValue`, `Decode.fromString`, `Decode.unsafeFromString`
* Add support for `char`
* Add link to the "extra coders" section when coders fail for missing types information
* Add `Decode.andMap` allowing to decoder large objects incrementally

### Changed

Expand Down
10 changes: 5 additions & 5 deletions paket.lock
Original file line number Diff line number Diff line change
Expand Up @@ -627,8 +627,8 @@ GROUP tests

GITHUB
remote: thoth-org/Thoth.Json
tests/BackAndForth.fs (51dd6bc3d1e347bdb3f5fd8fbdee91f1d8ed9a4f)
tests/Decoders.fs (51dd6bc3d1e347bdb3f5fd8fbdee91f1d8ed9a4f)
tests/Encoders.fs (51dd6bc3d1e347bdb3f5fd8fbdee91f1d8ed9a4f)
tests/ExtraCoders.fs (51dd6bc3d1e347bdb3f5fd8fbdee91f1d8ed9a4f)
tests/Types.fs (51dd6bc3d1e347bdb3f5fd8fbdee91f1d8ed9a4f)
tests/BackAndForth.fs (b01cdf639076bdf6e2d5c6a5cec1e86e99c03ab9)
tests/Decoders.fs (b01cdf639076bdf6e2d5c6a5cec1e86e99c03ab9)
tests/Encoders.fs (b01cdf639076bdf6e2d5c6a5cec1e86e99c03ab9)
tests/ExtraCoders.fs (b01cdf639076bdf6e2d5c6a5cec1e86e99c03ab9)
tests/Types.fs (b01cdf639076bdf6e2d5c6a5cec1e86e99c03ab9)
23 changes: 23 additions & 0 deletions src/Decode.fs
Original file line number Diff line number Diff line change
Expand Up @@ -748,6 +748,29 @@ module Decode =
// Object builder ///
////////////////////

/// <summary>
/// Allow to incrementally apply a decoder, for building large objects.
/// </summary>
/// <example>
/// <code lang="fsharp">
/// type Point =
/// {
/// X : float
/// Y : float
/// }
///
/// module Point =
/// let create x y = { X = x; Y = y }
///
/// let decode =
/// Decode.succeed create
/// |> Decode.andMap (Decode.field "x" Decode.float)
/// |> Decode.andMap (Decode.field "y" Decode.float)
/// </code>
/// </example>
let andMap<'a, 'b> : 'a Decoder -> ('a -> 'b) Decoder -> 'b Decoder =
map2 (|>)

type IRequiredGetter =
abstract Field : string -> Decoder<'a> -> 'a
abstract At : List<string> -> Decoder<'a> -> 'a
Expand Down

0 comments on commit ec8964b

Please sign in to comment.