Home freenode/#haskell: Logs Calendar

Logs: freenode/#haskell

←Prev  Next→
Page 1 .. 378 379 380 381 382 383 384 385 386 387 388 .. 5022
502,152 events total
2020-10-03 01:59:47 nnst^ joins (nnst@ip98-184-89-2.mc.at.cox.net)
2020-10-03 01:59:55 × justanotheruser quits (~justanoth@unaffiliated/justanotheruser) (Ping timeout: 240 seconds)
2020-10-03 02:00:01 × nineonine quits (~nineonine@216.81.48.202) (Remote host closed the connection)
2020-10-03 02:00:35 nineonine joins (~nineonine@216.81.48.202)
2020-10-03 02:02:30 thir joins (~thir@p200300f27f0fc60004d129737887aa72.dip0.t-ipconnect.de)
2020-10-03 02:02:41 snakemasterflex joins (~snakemast@213.100.206.23)
2020-10-03 02:04:45 × nineonine quits (~nineonine@216.81.48.202) (Ping timeout: 240 seconds)
2020-10-03 02:06:01 <dsal> > [Right 1, Right 2, Left 3, Right 4, Left 5] & traversed . _Left %~ (^2) -- cohn: you can also do stuff where prisms point you a particular way.
2020-10-03 02:06:03 <lambdabot> [Right 1,Right 2,Left 9,Right 4,Left 25]
2020-10-03 02:06:17 <cohn> oh cool.
2020-10-03 02:06:27 × thir quits (~thir@p200300f27f0fc60004d129737887aa72.dip0.t-ipconnect.de) (Ping timeout: 240 seconds)
2020-10-03 02:06:32 <cohn> maybe I can use that to pull the data out of my lens result
2020-10-03 02:07:05 × snakemasterflex quits (~snakemast@213.100.206.23) (Ping timeout: 240 seconds)
2020-10-03 02:07:14 <dsal> In my case, I get a big blob of results that includes both superchargers and destination chargers as different JSON results, but my charger type supports both and then lets me disambiguate later if I need to.
2020-10-03 02:08:44 × nbloomf quits (~nbloomf@2600:1700:83e0:1f40:f016:8714:fb84:1abd) (Quit: My MacBook has gone to sleep. ZZZzzz…)
2020-10-03 02:08:45 conal joins (~conal@107.181.166.148)
2020-10-03 02:09:38 <cohn> I have a value "x" with type "x :: vector-0.12.1.2:Data.Vector.Vector Value" but I'm not sure how to get the values out. I thought you could use the "!" operator on a vector
2020-10-03 02:10:11 <cohn> but it appears that it's storing an Aeson Value type that I'm not sure how to deal with.
2020-10-03 02:12:50 <dsal> I kind of wish I could aeson with a bot here, but... what lens library are you using?
2020-10-03 02:13:07 × ericsagnes quits (~ericsagne@2405:6580:0:5100:4db2:8fe2:8bd1:e1c0) (Ping timeout: 240 seconds)
2020-10-03 02:13:13 <cohn> both "Control.Lens" and "Data.Aeson.Lens"
2020-10-03 02:13:14 falafel joins (~falafel@2605:e000:1527:d491:a806:37fa:6971:2798)
2020-10-03 02:14:00 <dsal> Yeah, but what library is the latter?
2020-10-03 02:14:12 <dsal> @package lens-aeson
2020-10-03 02:14:12 <lambdabot> https://hackage.haskell.org/package/lens-aeson
2020-10-03 02:14:55 <cohn> checking.
2020-10-03 02:15:17 <cohn> yea, should be lens-aeson
2020-10-03 02:15:20 <dsal> The docs on that one show you how to use the prisms over value.
2020-10-03 02:16:00 <dsal> Do you have a small sample of your JSON and what you want to do with it?
2020-10-03 02:16:32 × taurux quits (~taurux@net-188-216-43-60.cust.vodafonedsl.it) (Ping timeout: 256 seconds)
2020-10-03 02:16:39 <dsal> `stack ghci` in this project wants to go grab a copy of ghc. So... this will take me a sec. heh
2020-10-03 02:17:09 <dsal> Oh wait, here's one where I have all the parts.
2020-10-03 02:17:15 <cohn> sure, I'm basically working with the Kodi JSON RPC API
2020-10-03 02:17:23 <cohn> fwiw: https://kodi.wiki/view/JSON-RPC_API/Examples
2020-10-03 02:17:41 × conal quits (~conal@107.181.166.148) (Quit: Computer has gone to sleep.)
2020-10-03 02:18:55 elliott__ joins (~elliott@pool-108-28-204-229.washdc.fios.verizon.net)
2020-10-03 02:19:18 <dsal> I looked up at your example above:
2020-10-03 02:19:33 <dsal> λ> "{\"foo\": [\"bar\", \"baz\"]}" ^.. key "foo" . _Array . folded . _String -> ["bar","baz"]
2020-10-03 02:19:56 <cohn> that's exactly what I'm trying to do... :D
2020-10-03 02:20:58 taurux joins (~taurux@net-188-152-1-196.cust.vodafonedsl.it)
2020-10-03 02:21:26 nbloomf joins (~nbloomf@2600:1700:83e0:1f40:2c94:3287:2d16:a9db)
2020-10-03 02:22:59 <dsal> λ> "{\"foo\": [\"bar\", \"baz\"]}" ^. key "foo" . nth 1 . _String -> "baz"
2020-10-03 02:23:47 × falafel quits (~falafel@2605:e000:1527:d491:a806:37fa:6971:2798) (Remote host closed the connection)
2020-10-03 02:24:18 falafel joins (~falafel@2605:e000:1527:d491:a806:37fa:6971:2798)
2020-10-03 02:24:29 × wroathe quits (~wroathe@c-68-54-25-135.hsd1.mn.comcast.net) (Quit: leaving)
2020-10-03 02:24:30 × nbloomf quits (~nbloomf@2600:1700:83e0:1f40:2c94:3287:2d16:a9db) (Client Quit)
2020-10-03 02:24:44 wroathe joins (~wroathe@c-68-54-25-135.hsd1.mn.comcast.net)
2020-10-03 02:25:13 <dsal> λ> "{\"foo\": [\"bar\", \"baz\"]}" ^.. members . values -- also, this sort of thing --> [String "bar",String "baz"]
2020-10-03 02:25:56 ericsagnes joins (~ericsagne@2405:6580:0:5100:f17c:daaf:122b:4823)
2020-10-03 02:26:25 × da39a3ee5e6b4b0d quits (~textual@n11211935170.netvigator.com) (Quit: My MacBook has gone to sleep. ZZZzzz…)
2020-10-03 02:26:35 <cohn> ok, here's a sample of the data I'm working with: https://pastebin.com/cYUUvXHe
2020-10-03 02:26:44 justanotheruser joins (~justanoth@unaffiliated/justanotheruser)
2020-10-03 02:27:59 <cohn> if "r" is my HTTP request response, I'm doing this: r ^? responseBody . key "result" . key "tvshows" . _Array
2020-10-03 02:28:26 <cohn> sorry, replace "^?" with "^."
2020-10-03 02:28:44 <dsal> Sure. I've got r as the responseBody in my repl
2020-10-03 02:30:08 <cohn> that gives me something like this:
2020-10-03 02:30:09 <cohn> [Object (fromList [("tvshowid",Number 157.0),("label",String "Show1")]),Object (fromList [("tvshowid",Number 164.0),("label",String "Show2")]),Object (fromList [("tvshowid",Number 31.0),("label",String "Show3")]),Object (fromList [("tvshowid",Number 162.0),("label",String "Show4")]),Object (fromList [("tvshowid",Number 163.0),("label",String "Show5")])]
2020-10-03 02:30:24 <cohn> so it looks like an array of objects to me
2020-10-03 02:30:31 <dsal> It's a list of an object.
2020-10-03 02:30:43 <cohn> I want to get the pairs of show ids and labels out
2020-10-03 02:31:31 Stanley|00 joins (~stanley00@unaffiliated/stanley00)
2020-10-03 02:32:43 <cohn> I assume it'd be easier to create a type for that and use FromJSON/ToJSON but it'd be nice to just explore the data without that stuff
2020-10-03 02:33:29 da39a3ee5e6b4b0d joins (~textual@n11211935170.netvigator.com)
2020-10-03 02:33:32 × HaskellYogi quits (~vivekrama@49.207.196.239) (Ping timeout: 256 seconds)
2020-10-03 02:33:42 <dsal> This is a little annoying. r ^.. key "result" . key "tvshows" . _Array . folded . to (\x -> (x ^? key "label" . _String, x ^? key "tvshowid" . _Integer))
2020-10-03 02:33:48 <dsal> But yeah, it'd be easier if you just had a type for that. :)
2020-10-03 02:34:05 × Stanley00 quits (~stanley00@unaffiliated/stanley00) (Ping timeout: 240 seconds)
2020-10-03 02:34:43 <cohn> heh, okay
2020-10-03 02:34:47 <dsal> You can't guarantee all of those things have the correct values, so they'd have to be maybes at best (which you could do in that lambda). Actually, that looks fun.
2020-10-03 02:35:41 <cohn> depends on your definition of fun... ; )
2020-10-03 02:36:08 <dsal> You can't guarantee all of those things have the correct values, so they'd have to be maybes at best (which you could do in that lambda). Actually, that looks fun.
2020-10-03 02:36:11 <dsal> Try this awful thing: r ^.. key "result" . key "tvshows" . _Array . folded . to (\x -> do { l <- x ^? key "label". _String; i <- x ^? key "tvshowid" . _Integer; pure (l,i)} ) . to sequenceA
2020-10-03 02:36:14 <dsal> Oops, sorry for the dup.
2020-10-03 02:37:15 <dsal> Oh wait, that was dumber than I meant.
2020-10-03 02:37:25 × elliott__ quits (~elliott@pool-108-28-204-229.washdc.fios.verizon.net) (Ping timeout: 264 seconds)
2020-10-03 02:37:25 × cr3 quits (~cr3@192-222-143-195.qc.cable.ebox.net) (Ping timeout: 240 seconds)
2020-10-03 02:37:30 <cohn> didn't work.
2020-10-03 02:37:56 <dsal> r ^.. key "result" . key "tvshows" . _Array . folded . to (\x -> do { l <- x ^? key "label". _String; i <- x ^? key "tvshowid" . _Integer; pure (l,i)} ) . _Just
2020-10-03 02:38:15 <dsal> That returns [("Show1",157),("Show2",164),("Show3",31),("Show4",162),("Show5",163)] for me.
2020-10-03 02:38:21 × Amras quits (~Amras@unaffiliated/amras0000) (Ping timeout: 272 seconds)
2020-10-03 02:39:26 <cohn> ah, okay. I'm getting an error but probably because my result is a lazy byte string
2020-10-03 02:39:45 <cohn> <interactive>:51:7: error:
2020-10-03 02:39:45 <cohn> • No instance for (AsValue
2020-10-03 02:39:45 <cohn> (Response Data.ByteString.Lazy.Internal.ByteString))
2020-10-03 02:39:45 <cohn> arising from a use of ‘key’
2020-10-03 02:39:47 <cohn> • In the first argument of ‘(.)’, namely ‘key "result"’
2020-10-03 02:40:21 <cohn> I need to redo this... I was using the http-conduit library but I should convert it all to Wreq
2020-10-03 02:40:56 <dsal> Yeah, you need to tell wreq to give you JSON
2020-10-03 02:41:30 <dsal> There's an `asJSON` call in there somewhere.
2020-10-03 02:41:33 <cohn> yep
2020-10-03 02:41:58 <dsal> Did you get it working?
2020-10-03 02:42:06 <cohn> should be something like r <- asJSON =<< get "http://blahblah"
2020-10-03 02:42:21 <dsal> Yeah, I end up burying that in helpers.
2020-10-03 02:42:24 <cohn> not yet.
2020-10-03 02:42:33 <dsal> jget :: (FromJSON j, MonadIO m) => String -> m j; jget u = view responseBody <$> liftIO (asJSON =<< get u)
2020-10-03 02:43:18 <cohn> nice
2020-10-03 02:44:46 <dsal> Once you get it working, delete this all and do it a sane way. :)
2020-10-03 02:45:19 <cohn> haha, will do. Thanks so much for all your help!
2020-10-03 02:45:56 <dsal> I do occasionally use this for weird one-off HTTP things, but making a type makes it easier. Then making lenses for my types gives me the same things with fewer conversion prism things.
2020-10-03 02:46:21 <cohn> I now see the benefit of types!

All times are in UTC.