Skip to content

Latest commit

 

History

History
41 lines (35 loc) · 814 Bytes

unflatten.md

File metadata and controls

41 lines (35 loc) · 814 Bytes

Function

unflatten — transform an array of key/value records into a record.

Synopsis

unflatten(val: [{key:string|[string],value:any}]) -> record

Description

The unflatten function converts the key/value records in array val into a single record. unflatten is the inverse of flatten, i.e., unflatten(flatten(r)) will produce a record identical to r.

Examples

Simple:

echo '[{key:"a",value:1},{key:["b"],value:2}]' |
  super -z -c 'yield unflatten(this)' -

=>

{a:1,b:2}

Flatten to unflatten:

echo '{a:1,rm:2}' |
  super -z -c 'over flatten(this) => (
           key[0] != "rm"
           |> yield collect(this)
         )
         |> yield unflatten(this)
  ' -

=>

{a:1}