week5 is hard

This commit is contained in:
Thorn Avery 2019-10-16 15:00:42 +13:00
parent 4dcfc0ee0d
commit f116fd9bab

53
201/week5/poke.hoon Normal file
View File

@ -0,0 +1,53 @@
/+ tapp, stdio
::
=>
|%
+$ state
$: pokedex=(map cord json)
==
+$ peek-data _!!
+$ in-poke-data [%noun =cord]
+$ out-poke-data ~
+$ in-peer-data ~
+$ out-peer-data
$% [%pokemon json]
==
++ tapp (^tapp state peek-data in-poke-data out-poke-data in-peer-data out-peer-data)
++ stdio (^stdio out-poke-data out-peer-data)
--
=>
|%
++ comment-to-tang
|= =tape
^- tang
%+ welp
%+ turn (rip 10 (crip tape))
|= line=cord
leaf+(trip line)
[leaf+""]~
++ urls
=/ base "https://pokeapi.co/api/v2/"
:* pokemon=(weld base "pokemon/")
==
--
=, async=async:tapp
=, tapp-async=tapp-async:tapp
=, stdio
::
%- create-tapp-poke-peer-take:tapp
^- tapp-core-poke-peer-take:tapp
|_ [=bowl:gall state]
::
++ handle-poke
|= =in-poke-data
=/ m tapp-async
=/ pokename cord.in-poke-data
^- form:m
::
?: (~(has by state) pokename)
~& 'pokemon already caught'
(pure:m (~(got by state) pokename))
=/ pokeurl (weld pokemon:urls (trip pokename))
%+ (set-timeout _json) (add now.bowl ~s15)
;< =json bind:m (fetch-json pokeurl)