Skip to content

Commit de62fd7

Browse files
committed
example for indexedArray
1 parent e084d8a commit de62fd7

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/Data/Codec/Argonaut.purs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,18 @@ type JIndexedCodec a =
148148
a a
149149

150150
-- | A codec for types that are encoded as an array with a specific layout.
151+
-- |
152+
-- | For example, given that we'd like to encode a Person as a 2-element array,
153+
-- | like so `[ "Karl", 25 ]`, we could write the following codec:
154+
-- |
155+
-- | ```purescript
156+
-- | type Person = { name ∷ String, age ∷ Int }
157+
-- |
158+
-- | JA.indexedArray "Test Object" $
159+
-- | { name: _, age: _ }
160+
-- | <$> _.name ~ index 0 JA.string
161+
-- | <*> _.age ~ index 1 JA.int
162+
-- | ```
151163
indexedArray a. String JIndexedCodec a JsonCodec a
152164
indexedArray name =
153165
bihoistGCodec

0 commit comments

Comments
 (0)