ChanServ changed the topic of #crystal-lang to: The Crystal programming language | http://crystal-lang.org | Crystal 0.30.1 | Fund Crystal's development: http://is.gd/X7PRtI | GH: https://github.com/crystal-lang/crystal | Docs: http://crystal-lang.org/docs/ | API: http://crystal-lang.org/api/ | Gitter: https://gitter.im/crystal-lang/crystal
lucasb has quit [Quit: Connection closed for inactivity]
<FromGitter> <Blacksmoke16> there is usually a better way to go about it
<FromGitter> <Blacksmoke16> That macro constant usage has recently been removed from Granite in favor of a more annotation based approach
<FromGitter> <renich> I need to know if v1 is an array of hashes, a hash or a string. https://play.crystal-lang.org/#/r/7ei4
<FromGitter> <renich> Please, help
<FromGitter> <tenebrousedge> it's a union type
<FromGitter> <renich> @tenebrousedge OK, how do I check?
<FromGitter> <tenebrousedge> if you want to narrow down what things it can be, you need to specify those types
<FromGitter> <Blacksmoke16> https://play.crystal-lang.org/#/r/7ei7 would prob do it, although ^ would be the better approach
<FromGitter> <renich> OK, thank you @Blacksmoke16
<FromGitter> <renich> and @tenebrousedge
<FromGitter> <tenebrousedge> yvw
<FromGitter> <tenebrousedge> @renich you might want to take a look at https://crystal-lang.org/api/0.30.1/YAML.html#mapping(_properties_,strict=false)-macro
<FromGitter> <Blacksmoke16> putting some ideas forward around (de-)serializing
<FromGitter> <tenebrousedge> lemme take a look at that in a bit
<FromGitter> <Blacksmoke16> on a similar note
<FromGitter> <Blacksmoke16> save you have
<FromGitter> <Blacksmoke16> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5d54b0f35178a724768c59f7]
<FromGitter> <Blacksmoke16> and you do `to_json` without providing the version
<FromGitter> <Blacksmoke16> would you expect the properties with the version annotations be serialized or not
<FromGitter> <Blacksmoke16> i could see it either way
<FromGitter> <Blacksmoke16> but im leaning to serializing them
<FromGitter> <Blacksmoke16> https://play.crystal-lang.org/#/r/7eil
<FromGitter> <Blacksmoke16> any idea on how to get the class name without the generic?
<FromGitter> <Blacksmoke16> `klass.name[0..-4]}}`
<FromGitter> <Blacksmoke16> that'll work :S
<FromGitter> <Blacksmoke16> 😮 til you can do this
<FromGitter> <Blacksmoke16> https://play.crystal-lang.org/#/r/7eir
<FromGitter> <Blacksmoke16> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5d54bd6f029a51607f96bb70]
<FromGitter> <Blacksmoke16> this is my new fav pattern
<FromGitter> <Blacksmoke16> @dscottboggs_gitlab will appreciate this
<FromGitter> <Blacksmoke16> and @vladfaust
<FromGitter> <Blacksmoke16> basically allows you to new up classes based on registered classes that have associated annotations
<FromGitter> <Blacksmoke16> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5d54bdbebeba830fff94ecec]
<FromGitter> <Blacksmoke16> if you remove the message from the annotation, it uses the default from the method
<FromGitter> <Blacksmoke16> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5d54bdf0c87a0963e771c048]
<FromGitter> <Blacksmoke16> so if you wanted to have a custom assertion you just inherit from the base, implement your two methods, and define the fields if any by making them ivars in your initializer
<FromGitter> <Blacksmoke16> giving them defaults if they are optional fields on the annotation
<FromGitter> <Blacksmoke16> not sure how to handle custom generic values yet tho (if its even possible)
<FromGitter> <Blacksmoke16> `@message = message || error_message` a bit cleaner
_whitelogger has joined #crystal-lang
<FromGitter> <tenebrousedge> @Blacksmoke16 how do you serialize procs though?
<FromGitter> <Blacksmoke16> Hell if I know
<FromGitter> <Blacksmoke16> I'd be curious to see an example of it
alex`` has quit [Ping timeout: 248 seconds]
ht_ has joined #crystal-lang
<FromGitter> <renich> I've created a yaml using the YAML.mapping macro. Is there a way to iterate over what I have? For exmaple: `my_yaml.each do |k, v|...`
ht_ has quit [Remote host closed the connection]
<FromGitter> <absolutejam_gitlab> A
<FromGitter> <absolutejam_gitlab> Sorry, fell
<FromGitter> <absolutejam_gitlab> Asleep
<FromGitter> <absolutejam_gitlab> @Blacksmoke16 I'm deserializing a yaml openapi spec then, as I parse the generated object tree, some of the objects can I include other objects properties
<FromGitter> <absolutejam_gitlab> So I wanna be able to
<FromGitter> <absolutejam_gitlab> Read properties from other classes essentially
<FromGitter> <absolutejam_gitlab> As in type, name, etc
<FromGitter> <andrius> Good morning. Can I do that with TCPSocket or need some mutex/locker before I send data? What is best practices? ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5d54f68bbeba830fff965b0d]
<FromGitter> <andrius> So the question is: does TCPSocket have its own build-in lock or I shall take care on that?
<FromGitter> <bararchy> lol compiler doesn't like it self XD ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5d54f6d0204d3d7385de41e9]
sagax has joined #crystal-lang
<FromGitter> <renich> I have a yaml file created with mapping. On the other hand, I have all the keys of that yaml in an array. I want to use `keys.each do |k|...` and build a csv row like: `csv.row location, hostname, k, yaml.$k`. My problem is that last one. I dunno how to pass the value of `k` to `yaml.` in order for it to get the value of that key.
<FromGitter> <renich> I want to dereference a variable and use it as the property name of `yaml`.
<FromGitter> <absolutejam_gitlab> If you are spitting out the yaml, does that mean you have the original data structure?
<FromGitter> <absolutejam_gitlab> So, could you store a k/v hash instead of just values?
<FromGitter> <renich> @absolutejam_gitlab yes, I do. But I created a `keys` method on the YAML.mapping definition.
<FromGitter> <renich> The thing is that I need to flatten in a special way a 3D array so it fits into a CSV (2D)
<FromGitter> <renich> btw, the `keys` method returns an array of strings and hashes and arrays of hashes.
<FromGitter> <renich> Looks somewhat like this but instead of parsing it, I used YAML.mapping: https://play.crystal-lang.org/#/r/7ei4
<FromGitter> <renich> The yaml file is similar to that, though.
<FromGitter> <renich> The relevant part of the code looks like this: ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5d54f93f90bba62a127b5229]
<FromGitter> <renich> The problem is that yaml.k fails.
<FromGitter> <renich> Or, more specifically: ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5d54fa0c2612bb718c6e099e]
<FromGitter> <renich> I've already tried: `yaml.{k}`, `{yaml.#{k}`, `yaml.$k` and others. Nothing works...
<FromGitter> <bararchy> So, it seems URI.escape does not behave the same as either URI.decode or URI.www_form_decode ... so which is the replacment ?
salival01 has joined #crystal-lang
<salival01> yo
<salival01> I was wondering if there was a way to call a macro inside an initalized class
flaviodesousa has joined #crystal-lang
<FromGitter> <renich> Good night to all! o/
flaviodesousa has quit [Quit: KVIrc 4.9.3 Aria http://www.kvirc.net/]
rohitpaulk has joined #crystal-lang
rohitpaulk has quit [Remote host closed the connection]
devil_tux has joined #crystal-lang
_whitelogger has joined #crystal-lang
devil_tux has quit [Ping timeout: 245 seconds]
devil_tux has joined #crystal-lang
<FromGitter> <absolutejam_gitlab> tackling this another way
<FromGitter> <absolutejam_gitlab> wait
<FromGitter> <absolutejam_gitlab> nevermind.
<FromGitter> <absolutejam_gitlab> Can I have a class that inherits from multiple parents?
<FromGitter> <absolutejam_gitlab> I know with Modules you can `extend`/`require`
<FromGitter> <rogerwelin_gitlab> Hi all! I'm dealing with json where I some fields are unknown. In the example below the "check google" and "check redis" are totally unknown. However the keys below it are known (Name & Status). ⏎ Ideally I want to use json mapping to return a known type but I don't know how to do that with unknown keys, is that possible? I could return JSON::Any, however I'm having a hard time grokking that one.
<FromGitter> ... Trying to iterate an object of JSON::Any just gives me "undefined method 'each' for JSON::Any". Someone having some recommendations in this case? ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5d553f7d53490e334df7277f]
<FromGitter> <naqvis> take a look into `JSON::Serializable` and `JSON::Serializable::Unmapped` ⏎ example direct from API documentation ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5d55420ea4efe3718d080385]
<FromGitter> <naqvis> @rogerwelin_gitlab ☝️
devil_tux has quit [Ping timeout: 248 seconds]
alex`` has joined #crystal-lang
<FromGitter> <rogerwelin_gitlab> @naqvis thanks, I've looked at that doc, but this example, you know the key of a, which I don't. I could leave everything unmapped, but the type A cannot be iterated either. must I add an enumerable for A then?
<FromGitter> <absolutejam_gitlab> Or I think you could make that a Hash with known classes beneath
<FromGitter> <tenebrousedge> @absolutejam_gitlab No, Crystal does not support multiple inheritance, except insofar as that can be accomplished by modules. But what do you need MI for that isn't adequately solved by modules?
<FromGitter> <naqvis> @rogerwelin_gitlab `Unmapped` values are stored in `Hash`, so you could either provide any wrapper against that or you can simply work on that `Hash`
<FromGitter> <absolutejam_gitlab> trying to whip up and example
<FromGitter> <Blacksmoke16> let me catch up
<FromGitter> <absolutejam_gitlab> actually, I think I may be wrong
<FromGitter> <Blacksmoke16> @renich could you use https://crystal-lang.org/api/master/Hash.html#key_for(value)-instance-method
<FromGitter> <absolutejam_gitlab> @tenebrousedge I'm just trying to reason about what I need. I think I'm doing it wrong, np
<FromGitter> <Blacksmoke16> salival01 got an example?
* FromGitter * tenebrousedge quacks like a rubber duck
<FromGitter> <Blacksmoke16> @rogerwelin_gitlab you could just define the type to be `Hash(String, String)`
<FromGitter> <Blacksmoke16> and would parse the obj as a hash
<FromGitter> <rogerwelin_gitlab> @naqvis how do I access the unmapped values? This gives me the same undefined method error ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5d554a5a1dadc42a117545a6]
<FromGitter> <Blacksmoke16> would be like `.unmapped_values` or something
<FromGitter> <Blacksmoke16> but prob easier to just define the type as a hash
<FromGitter> <rogerwelin_gitlab> @Blacksmoke16 yeah, that would be ideal, however I don't quite how to achieve that when I don't know the name of the key
<FromGitter> <Blacksmoke16> you dont have to know it
<FromGitter> <Blacksmoke16> https://play.crystal-lang.org/#/r/7ek4
<FromGitter> <Blacksmoke16> it'll just capture the obj as a hash
<FromGitter> <absolutejam_gitlab> ^ I tried to do this as an example but wrapped it in a class and then got stuck haha
<FromGitter> <absolutejam_gitlab> https://play.crystal-lang.org/#/r/7ek2
<FromGitter> <absolutejam_gitlab> But obviously that won't work, derp
<FromGitter> <naqvis> @rogerwelin_gitlab you can access unmapped keys via property `json_unmapped`
<FromGitter> <naqvis> Macro will inject this key in your class
<FromGitter> <rogerwelin_gitlab> @naqvis ah thanks, just found it in the docs :)
<FromGitter> <naqvis> ywc
<FromGitter> <rogerwelin_gitlab> @Blacksmoke16 awesome, exactly what I was after. much appreciated
<FromGitter> <Blacksmoke16> np
devil_tux has joined #crystal-lang
lucasb has joined #crystal-lang
Jenz has joined #crystal-lang
* Jenz o/
devil_tu1 has joined #crystal-lang
devil_tux has quit [Ping timeout: 248 seconds]
duane has joined #crystal-lang
<FromGitter> <j8r> Crystal is unusable this days
<FromGitter> <j8r> shards can't handle more than 8+ dependencies, aarch64 is broken
ht_ has joined #crystal-lang
<rkeene> j8r, There's always Tcl ;-)
<FromGitter> <j8r> lol
devil_tu1 has quit [Ping timeout: 248 seconds]
<rkeene> Hmm ?
<FromGitter> <kniknoo> Ok, I've read through the LLVM intro until I hit a wall in comprehension (Arduino is the closest I've come to C++). Then I read about Charley-Lang, so I read the source for it and it starts to get over my head too quick, and I read crystal/compiler macros, lexer, ast... maybe a few others... I can grok about 30% of it. I need to step it back to simple, yet using what crystal constructs there are. I am good
<FromGitter> ... with how a lexer needs to work, and that a parser needs to generate a series of AST nodes based on token patterns, and that an interpreter reads those nodes and responds with the related construct in the target output language. I'm so lost about the context of what all the built in AST nodes are and what all the macros are an ... [https://gitter.im/crystal-lang/crystal?at=5d5573604e17537f52381dc1]
<FromGitter> <tenebrousedge> is there a specific problem you're trying to solve?
<FromGitter> <tenebrousedge> would writing tests help?
<FromGitter> <kniknoo> I'm trying to learn compiler/transpiler design at the most fundamental level via LLVM. Since crystal is an LLVM language, I presume that there are some helpers to simplify the process. Right now I understand it in theory and can generate a basic token. I'm trying to understand what it means in crystal to generate an Abstract Syntax Tree and then interpret that tree.
sagax has quit [Remote host closed the connection]
<FromGitter> <tenebrousedge> you've been looking at the Crystal tests that generate the LLVM-IR ?
<FromGitter> <kniknoo> Ah, good point. I'm still new to other people's code so I've yet to learn that tests are where the real docs reside, as you've suggested before. I'll jump in there. It's just constructed for such a high level language and I want to start with a language that can recognize "def" -> "end" as a "subroutine", recognize integer variables, and run math equations. I'd start by showing how to do that much in crystal
<FromGitter> ... and send it to LLVM.
<FromGitter> <tenebrousedge> sounds LISPy
<FromGitter> <kniknoo> Perhaps. Goal is to be able to generate a toy language piece by piece. I have steps to learn in mind more than an end goal purpose.
<FromGitter> <tenebrousedge> you're aware of "NAND to Tetris", yeah?
<FromGitter> <kniknoo> Yes. Just finished up to the Assembler a couple days ago. Now I must purchase the book to continue or try to dive head first into something related, the latter of which I've been trying.
<FromGitter> <kniknoo> Concrete goal is a VM that emulates a TIS-100 node network. I have a virtual ALU and ASM parser spec in mind for it, but I need to learn how to build the VM, which will require some of this knowledge.
<FromGitter> <tenebrousedge> well it sounds like you're on the right track
<FromGitter> <kniknoo> Thanks! I can't wait to put some newfound understanding of how declarative HDL works toward designing some things on my FPGA. It was way over my head when someone gave it to me, I could get a basic hello world.
<FromGitter> <kniknoo> Ok, I see now. I was being too literal about LLVM's terms on their tutorial. Codegen is what I'm missing looking at.
devil_tux has joined #crystal-lang
<FromGitter> <kniknoo> ...or I hadn't read ahead.
<FromGitter> <tenebrousedge> o.o
<FromGitter> <kniknoo> I'm just so lost by what's going on in their parser example.
<FromGitter> <kniknoo> It makes more sense by codegen, but I'm at a point where I basically understand an AST as a list of hashes.
devil_tux has quit [Ping timeout: 248 seconds]
<FromGitter> <kniknoo> Oh FFS. I think it's being a burnout that's the problem. I just reviewed chap2 and somehow I got onto the full code listing page...
<FromGitter> <asterite> @kniknoo you should probably read the kaleidoscope tutorial for llvm, it'll be much simpler
<FromGitter> <asterite> also, cool that you are emulating TIS-100! (I just played a couple of levels but plan to continue playing if I have time)
<FromGitter> <kniknoo> That's what I'm reading. But NOW, I realize that it's confusingly both in c++ and Ocaml. I don't know either, but the differences between them are helping me to figure out what's c++ boilerplate and what's necessary.
<FromGitter> <kniknoo> I love Zachtronics! I want to do up this wild re-implementation of TIS, and I also have some ideas in mind for an exapunks inspired game that uses cards with assembly control flow and bitwise operations to create a dynamic gameboard for a version of their hacker battles.
<FromGitter> <kniknoo> But I love the simplicity of the languages so much that I actually want to try writing some generic assemblers for them as a means of mapping an inline ASM spec for micro-operations.
<FromGitter> <j8r> mps I run git bisect
<mps_> j8r: did you found something which could be of the help
sagax has joined #crystal-lang
<FromGitter> <j8r> not for now mps, it's long
<FromGitter> <j8r> maybe it's just https://github.com/crystal-lang/crystal/pull/8065
<FromGitter> <j8r> don't know (yet?)
ht__ has joined #crystal-lang
ht_ has quit [Ping timeout: 252 seconds]
<FromGitter> <j8r> that's 64bits so unlikely. I run out of memory compiling specs
<mps_> just read it but don't understand, TBH
ht__ is now known as ht_
<mps_> in my result 'out of memory' seems to be because low address and not exhausted memory
<FromGitter> <j8r> for me compiling specs for 0.29.0 use all my memory
<FromGitter> <j8r> and in 0.30.0 there are invalid memory access
<mps_> true for 0.29, I had to add 4GB swap to 6GB RAM
<mps_> for 0.30 i had to increase swap to 8GB
<FromGitter> <j8r> I suggest them to make the split spec public but they didn't want to
<mps_> hmm, I see, and agree with you
<FromGitter> <asterite> you can use it with the env vars
<mps_> asterite: please give recipe, I'm not sure which env and what
<FromGitter> <j8r> `CRYSTAL_SPEC_COMPILER_THREADS` isn't enough
<FromGitter> <asterite> Just pass SPEC_SPLIT=0%4 to run every spec modulo 4 == 0, and so on
<mps_> aha, thanks
<FromGitter> <j8r> good to know yes
<FromGitter> <j8r> anyway I'm on 0.29, the only thing I can do is zwap
<mps_> I've built 0.27 and 0.28 with 4GB RAM and zswap but suspect I could do that for 0.29 and 0.30
rohitpaulk has joined #crystal-lang
fyber has joined #crystal-lang
Jenz has quit [Ping timeout: 258 seconds]
lvmbdv has quit [Ping timeout: 248 seconds]
lvmbdv has joined #crystal-lang
devil_tux has joined #crystal-lang
rohitpaulk has quit [Ping timeout: 245 seconds]
lvmbdv has quit [Ping timeout: 248 seconds]
lvmbdv has joined #crystal-lang
devil_tux has quit [Ping timeout: 272 seconds]
alex`` has quit [Ping timeout: 244 seconds]
alex`` has joined #crystal-lang
MasterdonX has quit [Read error: Connection reset by peer]
<FromGitter> <renich> @Blacksmoke16 thanks! I'll try it in a little while.
salival01 has left #crystal-lang [#crystal-lang]
<FromGitter> <j8r> mps I was able to compile specs with LLVM5
<FromGitter> <j8r> but I was using crystal 0.29 :/
<FromGitter> <j8r> forget it, I try with 0.30
<mps_> we have 0.29 on aarch64 in v3.10 alpine release, it is built llvm5
fyber has quit [Remote host closed the connection]
<FromGitter> <j8r> The bisect will be long, because I will need to compile Crystal then all specs, on Qemu :/
ht_ has quit [Remote host closed the connection]
MasterdonX has joined #crystal-lang
sagax has quit [Remote host closed the connection]
duane has quit [Ping timeout: 245 seconds]
<FromGitter> <asterite> 1) 30.0 can't work with LLVM >= 6 compiled with assertions (maybe it even fails without them). You have to use 0.30.1 (in case it helps)
<mps_> just received PRIVMSG but looks like my trigger in irssi failed to reformat it correctly
<mps_> anyone sent msg to me?
<rkeene> Nobody loves you
<mps_> hehe, and especially my script to make gitgutter gateway acceptable in irssi ;-)
<FromGitter> <sam0x17> if I'm getting "cannot convert from `SomeType` to `SomeOtherType`" errors, is there some drop-in method I can create that will make crystal know how to convert from `SomeType` to `SomeOtherType`, or am I out of luck?
<FromGitter> <watzon> @sam0x17 depends on the situation, but generally you're out of luck
<FromGitter> <sam0x17> whats the situation where it depends? lol
<FromGitter> <watzon> It depends on what types you're trying to convert. There are lots of situations where you'd think it should work, but it doesn't
<FromGitter> <watzon> Apparently the compiler isn't smart enough for that yet
<FromGitter> <sam0x17> Array(Int64) to and from Array(String)
<FromGitter> <watzon> Yeah you can't do that, for whatever reason. The only way to do that would be to use `map`. So `arr.map!(&.to_s)` should work.
<FromGitter> <sam0x17> some idiot at my work defined this db column as a postgres string array when its an array of ids, so this orm (correctly) doesnt let me trick it into letting me
<FromGitter> <sam0x17> so I'll just have to keep using strings :/
<FromGitter> <watzon> You can do the conversion using `map`. It shouldn't have much of a performance impact, if any ⏎ The only place where you'll run into trouble is if the value isn't a valid int
<FromGitter> <sam0x17> yeah no thats what I was trying to do clear orm doesn't let me basically because it checks the types before it runs the conversion code
<FromGitter> <Blacksmoke16> what orm @sam0x17 ?
<FromGitter> <Blacksmoke16> can you not define a converter?
<FromGitter> <sam0x17> https://github.com/anykeyh/clear
<FromGitter> <sam0x17> I have this in my model: ⏎ ⏎ ``` column collaborator_ids : Array(String) ⏎ column manager_ids : Array(String)``` [https://gitter.im/crystal-lang/crystal?at=5d55d7d31db76d0ffedc6002]
<FromGitter> <sam0x17> yeah
<FromGitter> <Blacksmoke16> could you uses that?
<FromGitter> <sam0x17> they dont work
<FromGitter> <Blacksmoke16> :(
<FromGitter> <sam0x17> for some reason the postgres array types are all janked with those
<FromGitter> <sam0x17> like its trying to use `Array(PG::StringArray)`
<FromGitter> <tenebrousedge> so you can't change `collaborator_ids: Array(Int32)` ?
<FromGitter> <sam0x17> which I thought should just be `PG::StringArray` (which I also dont know how to instantiate)
<FromGitter> <sam0x17> you get sql errors if you do that
<FromGitter> <sam0x17> so I tried writing a converter for Array(Int64) <=> Array(String) but Array(String) is also a magically supported type that isn't in the valid types list
<FromGitter> <tenebrousedge> can you change the schema?
<FromGitter> <tenebrousedge> (sorry if I'm asking stupid questions)
<FromGitter> <sam0x17> no thats the best solution obviously
<FromGitter> <sam0x17> I really dont want to lets put it that way
<FromGitter> <sam0x17> would be a massive migration
<FromGitter> <sam0x17> this is a 5 year old table from a large rails app
<FromGitter> <sam0x17> right now the easiest solution is to just use custom getters and setters that have a different name on the model
<FromGitter> <Blacksmoke16> rip
<FromGitter> <sam0x17> so yeah, you feel my pain lol
<FromGitter> <sam0x17> would `PG::StringArray` in theory be coming from the `pg` shard?
<FromGitter> <Blacksmoke16> dont think so
<FromGitter> <sam0x17> I tried this converter: ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5d55d97d5178a7247694ee09]
<FromGitter> <Blacksmoke16> and what happens?
<FromGitter> <sam0x17> it complains that my maps are still Array(String) because I dont know how to make an Array(PG::StringArray)
<FromGitter> <Blacksmoke16> oh
<FromGitter> <sam0x17> `Error: type must be (Array(JSON::Any) | Array(PG::BoolArray) | Array(PG::CharArray) | Array(PG::Float32Array) | Array(PG::Float64Array) | Array(PG::Int16Array) | Array(PG::Int32Array) | Array(PG::Int64Array) | Array(PG::NumericArray) | Array(PG::StringArray) | Array(PG::TimeArray) | Bool | Char | Clear::Expression::UnsafeSql | Float32 | Float64 | Hash(String, JSON::Any) | Int16 | Int32 | Int64 | Int8 |
<FromGitter> ... JSON::Any | PG::Geo::Box | PG::Geo::Circle | PG::Geo::Line | PG::Geo::LineSegment | PG::Geo::Path | PG::Geo::Point | PG::Geo::Polygon | PG::Numeric | Slice(UInt8) | String | Time | UInt16 | UInt32 | UInt64 | UInt8 | Nil), not (Array(PG::StringArray) | Array(String))`
<FromGitter> <Blacksmoke16> try like `x.map(&.to_s).as(Array(PG::StringArray))`
<FromGitter> <sam0x17> I think I had that a few mins ago let me try again on both sides of the converter
<FromGitter> <tenebrousedge> you should probably alias `Array(PG::StringArray)`
<FromGitter> <sam0x17> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5d55da44beba830fff9d24d0]
<FromGitter> <watzon> I can't find where StringArray is defined anywhere
<FromGitter> <sam0x17> yeah I've been looking
<FromGitter> <tenebrousedge> what's in the `StringArray`?
<FromGitter> <tenebrousedge> do you need to iterate over that?
<FromGitter> <sam0x17> what's interesting is when I do `.to_i` on the items of the `Array(PG::StringArray)` it actually says did you mean `to_a`?
<FromGitter> <Blacksmoke16> @watzon ikr?
<FromGitter> <tenebrousedge> `x.flat_map {|arr| arr.map(&.to_i) }`
<FromGitter> <watzon> I've looked all over
<FromGitter> <Blacksmoke16> aha!
<FromGitter> <sam0x17> `Array(PG::StringArray)` seems to be how it represents postgres string arrays when talking to postgres, but its like its abusing the syntax for some reason because its really an array of arrays I think
<FromGitter> <watzon> @sam0x17 you should try searching your lib directory for `StringArray` and see if you can find it
<FromGitter> <Blacksmoke16> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5d55dabf5178a7247694f79b]
<FromGitter> <Blacksmoke16> ` array_type String, 1009`
<FromGitter> <j8r> @asterite Thanks. I use LLVM 5 to avoid this type of issues
<FromGitter> <sam0x17> so what is it really then?
<FromGitter> <Blacksmoke16> a union of String and Array(String)
<FromGitter> <sam0x17> ah
<FromGitter> <sam0x17> that I could probably disect
<FromGitter> <sam0x17> so since its `Array(PG::StringArray)` its really a `Array(String | Array(String))`?
<FromGitter> <tenebrousedge> seems so
<FromGitter> <sam0x17> any ideas why its being nested in an outer array lol?
<FromGitter> <sam0x17> my initial thought was that there is some syntactical abuse going on somewhere that makes that convenient
<FromGitter> <tenebrousedge> could be that there are methods that only return one result?
<FromGitter> <sam0x17> so I should just assume the outer array always has 0 or 1 elements I'm thinking
<FromGitter> <tenebrousedge> why not just flatten it and then convert whatever you have?
<FromGitter> <j8r> like a Tuple
<FromGitter> <j8r> nvm, depends of what elements they are
<FromGitter> <sam0x17> I have I think the first part of the converter working, however my assumption that `Array(PG::StringArray) == Array(String | Array(String))` seems not to be working: ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5d55ddc4a4efe3718d0cbce5]
<FromGitter> <sam0x17> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5d55ddea7d56bc60805e59d2]
<FromGitter> <tenebrousedge> Array(String? | Array(String)) , wasn't it?
<FromGitter> <sam0x17> yeah
<FromGitter> <sam0x17> which should be compatible with `Array(Array(String))`
<FromGitter> <Blacksmoke16> `[x.map(&.to_s).as(Array(PG::StringArray))}].as(Array(PG::StringArray))`
<FromGitter> <Blacksmoke16> or something like that
<FromGitter> <sam0x17> aha ok
<FromGitter> <sam0x17> `Error: can't cast Array(String) to PG::StringArray`
<FromGitter> <Blacksmoke16> so try like
<FromGitter> <sam0x17> now I now longer feel bad for giving up on this last night xD
<FromGitter> <sam0x17> is there some introspection I can use to get crystal to tell me what PG::StringArray is in great detail, because I'm starting to think its not what we think it is
<FromGitter> <tenebrousedge> `p!`
<FromGitter> <Blacksmoke16> `[x.map(&.to_s.as(PG::StringArray)).as(Array(PG::StringArray))}].as(Array(PG::StringArray))`
<FromGitter> <sam0x17> ok I actually chuckled this time:
<FromGitter> <sam0x17> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5d55e0d853490e334dfc33fd]
<FromGitter> <Blacksmoke16> oo so just remove the out `[]` and call it a day
<FromGitter> <sam0x17> trying it
<FromGitter> <sam0x17> I THINK it may be working
<FromGitter> <sam0x17> getting other unrelated errors now
<FromGitter> <sam0x17> thanks so much!!
<FromGitter> <Blacksmoke16> 👍 np
<FromGitter> <sam0x17> ah, now I just have to replace `[` with `{` and `]` with `}` because postgres is weird
<FromGitter> <sam0x17> `ERROR: malformed array literal: "[]"`
<FromGitter> <Blacksmoke16> :p
<FromGitter> <sam0x17> hmmmm I might be able to bypass whole thing by just returning a correctly formatted string
<FromGitter> <sam0x17> (after all that its just like yeah index out of bounds with no line number xD)
<FromGitter> <sam0x17> hhaa ok cool
<FromGitter> <sam0x17> index out of bounds was my fault in other part of converter
<FromGitter> <sam0x17> and both methods work (super complicated one and string one)
<FromGitter> <sam0x17> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5d55e3d01dadc42a1179f4e1]
<FromGitter> <sam0x17> (ignore debugging code)
<FromGitter> <Blacksmoke16> Nice one
<FromGitter> <sam0x17> hah ok so here is final code that works in all situations: ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5d55e94553490e334dfc7902]
<FromGitter> <sam0x17> and yeah, if anyone knows a cleaner way of chaining gsub removals I'm down.. isn't delete a thing?
<FromGitter> <tenebrousedge> yes
<FromGitter> <tenebrousedge> `delete("'\[]")`
<FromGitter> <sam0x17> beautiful thx
<FromGitter> <tenebrousedge> but watch the escaping D:
<FromGitter> <sam0x17> works great, thx @Blacksmoke16 and @tenebrousedge ! ⏎ ⏎ ```x.to_s.delete("'\"[]").split(",").map { |item| item.to_i64 }``` [https://gitter.im/crystal-lang/crystal?at=5d55ea3b1db76d0ffedce61e]
<FromGitter> <tenebrousedge> ```"[]\'".delete("[]\'") #=> "" ⏎ "[]\\\''".delete("'\[]") #=> "\\"``` [https://gitter.im/crystal-lang/crystal?at=5d55ea3c029a51607f9f8833]
sagax has joined #crystal-lang
<FromGitter> <sam0x17> nice, confirmed that it works on the production db 👍