factor out map-to-json

This commit is contained in:
Anton Dyudin 2016-02-17 15:50:03 -08:00
parent 73bcc66007
commit bf2164054d
4 changed files with 11 additions and 17 deletions

8
lib/map-to-json.hoon Normal file
View File

@ -0,0 +1,8 @@
:: hoon data to json
::
:::: /hoon/map-to-json/lib
::
/? 310
|* {a/_cord b/_json} :: XX {a/$-(* cord) b/$-(* json)}
|= c/(map _+<.a _+<.b)
(jobe (turn (~(tap by c)) |*(d/^ [(a -.d) (b +.d)])))

View File

@ -12,12 +12,6 @@
~[ele]
(zing (turn c.ele ..$))
::
++ map-to-json :: hoon data to json
|* {a/$-(* cord) b/$-(* json)}
|* c/(map) ^- json :: XX c=(map _+<.a _+<.b)
~! c
(jobe (turn (~(tap by c)) |*(* [(a +<-) (b +<+)])))
::
:: a.b_c.d => [[%a %b] [%c %d]]
:: a.b_c, a_b__c => [[%a %b] %c]
:: a_b_c, a__b_c => [%a [%b %c]]

View File

@ -3,7 +3,7 @@
::
/? 310
/- talk
/+ talk
/+ talk,map-to-json
!:
=+ talk
|_ gam/(list telegram)
@ -127,20 +127,12 @@
++ jope |=(a/ship (jape +:<a>)) ::[%s (crip +:(scow %p a))])
++ joke |=(a/tank [%s (role (turn (wash 0^80 a) crip))])
++ jode |=(a/time (jone (div (mul (sub a ~1970.1.1) 1.000) ~s1)))
++ jome :: stringify keys
|* {a/_cord b/_json}
|= c/(map _+<.a _+<.b)
(jobe (turn (~(tap by c)) (both a b)))
::
++ both :: cons two gates
|* {a/_* b/_*}
|=(c/_[+<.a +<.b] [(a -.c) (b +.c)])
::
++ thot
|= thought
(jobe serial+(jape <p>) audience+(audi q) statement+(stam r) ~)
::
++ audi (jome parn jove)
++ audi (map-to-json parn jove)
++ bouq
|= a/bouquet
a+(turn (~(tap in a)) |=(b/path a+(turn b |=(c/knot s+c))))

View File

@ -2,7 +2,7 @@
:::: /hoon/index/tree/mar
::
/? 310
/+ tree,react
/+ tree,react,map-to-json
[. tree react]
!:
::::