Skip to content

Commit

Permalink
Format docs
Browse files Browse the repository at this point in the history
I have issues.
  • Loading branch information
zwilias committed Nov 14, 2019
1 parent 99abe09 commit e2b62df
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 19 deletions.
2 changes: 1 addition & 1 deletion .gitignore
@@ -1,5 +1,5 @@
elm-stuff
node_modules
tests/Doc
tests/VerifyExamples
.coverage
docs.json
34 changes: 16 additions & 18 deletions src/Json/Decode/Exploration.elm
Expand Up @@ -266,7 +266,7 @@ decodeString decoder jsonString =

{-| Reduce JSON down to what is needed to ensure decoding succeeds.
Similar the [`stripString`](#stripString) docs for more details and an example.
See the [`stripString`](#stripString) docs for more details and an example.
-}
stripValue : Decoder a -> Value -> Result Errors Value
Expand All @@ -286,18 +286,15 @@ stripValue (Decoder decoderFn) val =

{-| Reduce JSON down to what is needed to ensure decoding succeeds.
This is useful if you are doing a build step where you want to
strip down your JSON data to the minimal amount needed by
your Decoder. Because of the purity of Elm's functions,
you can safely strip out unused data assuming that you
use the exact same Decoder to strip the JSON as you use
when you re-run it against the stripped JSON. Be sure
your Decoder doesn't depend on any parameters which
will vary between at build-time and run-time or
you will lose this guarantee.
This is useful if you are doing a build step where you want to strip down your
JSON data to the minimal amount needed by your Decoder. Because of the purity of
Elm's functions, you can safely strip out unused data assuming that you use the
exact same Decoder to strip the JSON as you use when you re-run it against the
stripped JSON. Be sure your Decoder doesn't depend on any parameters which will
vary between at build-time and run-time or you will lose this guarantee.
You can also take a look at the `validateStrip` test
cases in [this test module](https://github.com/zwilias/json-decode-exploration/blob/master/tests/SimpleTests.elm).
You can also take a look at the `validateStrip` test cases in [this test
module](https://github.com/zwilias/json-decode-exploration/blob/master/tests/SimpleTests.elm).
import Json.Decode.Exploration as Decode exposing (Decoder)
Expand All @@ -306,13 +303,13 @@ stripValue (Decoder decoderFn) val =
jsonValue =
"""
{
"topLevelUsed": 123,
"partiallyUsed": [
"topLevelUsed": 123,
"partiallyUsed": [
{"used": "Hi! This is read by Decode.index so this Object will be included.", "unused": "Please ignore me"},
{"used": "This whole Object is stripped out because it isn't read by Decode.index!", "unused": "This field is always ignored"}
],
"unused": 456,
"nestedUnused": "This gets stripped out of the final JSON"
"unused": 456,
"nestedUnused": "This gets stripped out of the final JSON"
}
"""
Expand All @@ -322,11 +319,12 @@ stripValue (Decoder decoderFn) val =
decoder =
Decode.map2 Record
(Decode.field "topLevelUsed" Decode.int)
(Decode.field "partiallyUsed" ( Decode.index 0 (Decode.field "used" Decode.string )))
(Decode.field "partiallyUsed"
(Decode.index 0 (Decode.field "used" Decode.string))
)
Decode.stripString decoder jsonValue
|> Result.mapError Decode.errorsToString
--> Ok """{"topLevelUsed":123,"partiallyUsed":[{"used":"Hi! This is read by Decode.index so this Object will be included."}]}"""
-}
Expand Down

0 comments on commit e2b62df

Please sign in to comment.