@@ -370,8 +370,7 @@ export namespace Decode {
370
370
export function many < T > ( child : Decoder < T > ) : Decoder < T [ ] >
371
371
372
372
/**
373
- * Take the value decoded by the given decoder and do something
374
- * with it.
373
+ * Take the value decoded by the given decoder and transform it.
375
374
*
376
375
* @param fn - Your mapping function
377
376
* @param child - The decoder to run before calling your function
@@ -381,7 +380,21 @@ export namespace Decode {
381
380
*
382
381
* @example
383
382
* ```typescript
384
- * // TODO
383
+ * // Add 42 to a number
384
+ * const add_42_decoder = Decode.map(value => value + 42, Decode.number);
385
+ *
386
+ * decode(add_42_decoder, 0) === 42
387
+ * decode(add_42_decoder, -42) === 0
388
+ * decode(add_42_decoder, 42) === 84
389
+ * decode(add_42_decoder, 'text') // Fails
390
+ *
391
+ * // Convert any value to its string representation.
392
+ * const to_string_decoder = Decode.map(value => String(value), Decode.unknown);
393
+ *
394
+ * decode(to_string_decoder, 42) === '42'
395
+ * decode(to_string_decoder, {}) === '[object Object]'
396
+ * decode(to_string_decoder, 'text') === 'text'
397
+ * decode(to_string_decoder, Symbol('my_symbol')) === 'Symbol(my_symbol)'
385
398
* ```
386
399
*/
387
400
export function map < A , B > ( fn : ( a : A ) => B , child : Decoder < A > ) : Decoder < B >
0 commit comments