RX14 changed the topic of #crystal-lang to: The Crystal programming language | http://crystal-lang.org | Crystal 0.26.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
return0e has quit [Remote host closed the connection]
return0e has joined #crystal-lang
return0e has quit [Remote host closed the connection]
<FromGitter> <Sija> howdy every1, how are y’all doin’? :)
marmotini_ has joined #crystal-lang
non-aristotelian has quit [Quit: non-aristotelian]
<FromGitter> <Blacksmoke16> o/
davic has quit [Ping timeout: 252 seconds]
davic has joined #crystal-lang
marmotini_ has quit [Ping timeout: 246 seconds]
<FromGitter> <Sija> any1 is planning some Crystal meetups in the euro-zone?
<FromGitter> <fenicks> @Sija Try the Paris meetup, one is coming: https://www.meetup.com/pariscrystal/
<FromGitter> <Sija> nice! although it’s too far for me atm :(
Heaven31415 has quit [Quit: Leaving]
<FromGitter> <fridgerator> Someone geneated a website that would create classes for you based on jason structures, anyone know what it is/
<FromGitter> <fridgerator> ?
<FromGitter> <Blacksmoke16> @fridgerator https://app.quicktype.io/
<FromGitter> <fridgerator> tytyty
<FromGitter> <Blacksmoke16> np
_whitelogger has joined #crystal-lang
greengriminal has joined #crystal-lang
greengriminal has quit [Client Quit]
greengriminal has joined #crystal-lang
rohitpaulk has joined #crystal-lang
greengriminal has quit [Ping timeout: 272 seconds]
greengriminal has joined #crystal-lang
greengriminal has quit [Quit: This computer has gone to sleep]
<FromGitter> <proyb6> Does this code allocate any new string or stack?
<FromGitter> <proyb6> p "hello"[1..-1]
rohitpaulk has quit [Ping timeout: 244 seconds]
<FromGitter> <aboeglin> @fenicks I don't see any coming, where do you see that ?
<FromGitter> <aboeglin> using HTTP::Server::Response: ⏎ ⏎ ```code paste, see link``` ⏎ ⏎ If anyone can explain me why and if using a NamedTuple is the prefered way when returning json from an http server. [https://gitter.im/crystal-lang/crystal?at=5bc57c3ff659e67772c2c9bc]
rohitpaulk has joined #crystal-lang
ua_ has quit [Ping timeout: 250 seconds]
<FromGitter> <Timbus> Looks like the compiler thinks you are passing a block to 'print', in the second example.
ua has joined #crystal-lang
<FromGitter> <fusillicode_twitter> Guys just to be sure, right now there is only one viable solution to query a mongo db instance from Crystal right?
<FromGitter> <fusillicode_twitter> 👉 https://github.com/datanoise/mongo.cr
<FromGitter> <fusillicode_twitter> oh, wait...there is also another one...a fork I presume https://github.com/kalinon/mongo.cr
rohitpaulk has quit [Ping timeout: 252 seconds]
<FromGitter> <j8r> Qqq1qqqqqqqaqqqaQaqqaaaA
<FromGitter> <fusillicode_twitter> 🤔
<FromGitter> <j8r> Omg the web mobile UI sucks
<FromGitter> <fusillicode_twitter> gitter app right?
<FromGitter> <j8r> Sorry, it sends message when i don't want (e.g switching to a tab)
<FromGitter> <fusillicode_twitter> lol
<FromGitter> <aboeglin> I find it pretty bad too compared to slack or discord
<FromGitter> <proyb6> Discord is lots better
<FromGitter> <aboeglin> But in my example above, shouldn't {}.to_json be evaluated before the print call ?
<FromGitter> <aboeglin> It seems odd to me
<FromGitter> <bew> @fenicks where do you see there's a crystal meetup coming in paris??
<FromGitter> <bew> @proyb6 your exemple will allocate a new string yes
<FromGitter> <aboeglin> You got excited about it as well Benoit ?
<FromGitter> <proyb6> @bew
<FromGitter> <proyb6> Any way my code you simply pass partial string without allocated?
<FromGitter> <proyb6> response << requesturl[5..-1]
<FromGitter> <proyb6> if I wanted to return only the URL after /user path as in /user/proyb6, only proyb6 and the rest will pass to the variable without allocating any resource? Not sure if that’s possible
<FromGitter> <fenicks> @bew a member of the staff answer my question in discussions.
<FromGitter> <fenicks> It's not planned for now but it's coming
<FromGitter> <bew> @proyb6 how are you going to use the partial string?
<FromGitter> <bew> @fenicks good to know! I'm living in paris, so yeah i'm exited :p
<FromGitter> <bew> +c
return0e has joined #crystal-lang
<FromGitter> <fenicks> @bew OK, me too
<FromGitter> <fenicks> I'm from Paris too
<FromGitter> <fenicks> 👍
moei has quit [Read error: Connection reset by peer]
moei has joined #crystal-lang
<FromGitter> <iSarCasm> Hello guys, is there any info about when new crystal release is coming?
<FromGitter> <bew> @fenicks cool! let's meet one day!
<FromGitter> <proyb6> @bew the string was actually sent to context.response to return string to the web browser
<FromGitter> <bew> @proyb6 you can try using `Slice`, you can get a slice from a String with `String#to_slice`, but note that it'll not play nicely with UTF-8
<FromGitter> <bew> I have a shard idea to make a StringView type, that will play well with UTF-8 and avoid allocating new Strings when all you want is to get a part of a string
<FromGitter> <bew> but there's no builtin way as far as i know
<FromGitter> <proyb6> I see, I look forward to try your shard if it will handle http routing like /user/:id that could be done uncomplicated
<FromGitter> <proyb6> I came across HN which I thought could be useful as a shard for C in crystal
<FromGitter> <proyb6> https://dangless.gaborkozar.me/
rohitpaulk has joined #crystal-lang
ashirase has quit [Ping timeout: 246 seconds]
Raimondi has quit [Read error: Connection reset by peer]
Raimondi has joined #crystal-lang
ashirase has joined #crystal-lang
_whitelogger has joined #crystal-lang
rohitpaulk has quit [Ping timeout: 250 seconds]
<jokke> is shards --production implying --release?
<FromGitter> <bew> No jokke
<FromGitter> <bew> It'll only install non-dev dependencies iirc
<jokke> hm ok
<FromGitter> <bew> @proyb6 dangless is for languages with manual memory management, which iz not the case for crystal
<FromGitter> <bew> About my shard, it'll not be aware of how you use it (e.g for http routes)
_whitelogger has joined #crystal-lang
_whitelogger has quit [Excess Flood]
_whitelogger has joined #crystal-lang
<FromGitter> <proyb6> @bew I see, that’s better
<FromGitter> <aboeglin> is there anything likes a find method on Array ? I checked in the API but couldn't find anything that seems suitable.
<FromGitter> <aboeglin> I have an array of Objects, and I need to find out if an object is part of that array.
<FromGitter> <aboeglin> I could possibly use something like &, and check the size of the intersection
rohitpaulk has joined #crystal-lang
<FromGitter> <aboeglin> something like: ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5bc5c5b0600c5f6423b9fe2d]
<FromGitter> <aboeglin> I'm just not sure if the intersection works by reference, which I assume, or by value, but it seems overkill though
<FromGitter> <bajro17> I need help with elasticsearch
<FromGitter> <bajro17> I need to write this ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5bc5c63f6e5a401c2d7dcece]
<FromGitter> <mamantoha> @aboeglin https://crystal-lang.org/api/0.26.1/Enumerable.html#find%28if_none%3Dnil%2C%26block%29-instance-method
<FromGitter> <bajro17> but I cant figure out from documentation how it work
<FromGitter> <mamantoha> @aboeglin something like this ⏎ ⏎ ```intersection = myArray.find { |i| i == myObject} ⏎ if insertion ⏎ # do something ⏎ end``` [https://gitter.im/crystal-lang/crystal?at=5bc5c6c3ef4afc4f28816ec3]
<FromGitter> <aboeglin> @mamantoha ah great thanks ! I haven't thought of checking super classes of Array
<FromGitter> <aboeglin> yes, in my case it's a bit different as I just need to check one field of my object, but it'll work great !
<FromGitter> <bararchy> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5bc5c6e8898e4e19edd90aa6]
<FromGitter> <bararchy> @bajro17 something like that?
<FromGitter> <bajro17> @bararchy I will try it now thank you so much
rohitpaulk has quit [Ping timeout: 244 seconds]
<FromGitter> <bew> @aboeglin if you just want if the object is in the array, you can use `includes?` https://crystal-lang.org/api/0.26.1/Enumerable.html#includes%3F(obj)-instance-method
<FromGitter> <aboeglin> @bew I found my solution, in that case I just needed to check if the object had 1 property equal, and includes would test reference equality I suppose as my object doesn't implement == operator
<FromGitter> <bew> ok perfect then
rohitpaulk has joined #crystal-lang
<jokke> is there something like a code style _checker_ for crystal (not crystal tool format)?
<jokke> i noticed crystal tool format can be run with --check but that doesn't give any output
<jokke> only exit code
<jokke> preferably something configurable
rohitpaulk has quit [Ping timeout: 272 seconds]
ashirase has quit [Read error: Connection reset by peer]
<z64> jokke: https://github.com/veelenga/ameba is probably the most popular that i know of
<jokke> z64: yeah it doesn't do any format checks though
<jokke> another question: how can i display all compile flags the running program was built with?
<z64> i see. it said on the tin it "enforces consistent crystal code style", i guess i don't know what that means then lol :p
<jokke> hm ok
<z64> i doubt there is anything like it though, the formatter itself by design is not configurable, one would have to completely write one from scratch i would imagine
<jokke> mh :/
<z64> if you're interested in formatter changes, i will usually stage all my files before running it. then the formatters changes will dirty the working copy diff so i can review them
<z64> usually with `git add -p` etc
<jokke> yeah
ashirase has joined #crystal-lang
marmotini_ has joined #crystal-lang
<FromGitter> <aboeglin> I have a question regarding classes. I see a lot of code with classes inside classes like this : ⏎ ⏎ ```class A ⏎ class B ⏎ end ⏎ end``` ⏎ ⏎ Is this syntax described somewhere ? Is it a way to namespace ? Is class A expected to be "used", meaning instantiated ? What is the use-case for this ? [https://gitter.im/crystal-lang/crystal?at=5bc5e44e64cfc273f9d6ad4f]
<FromGitter> <j8r> Yes this is a way to namespace.
<FromGitter> <aboeglin> how would one use it then ?
<FromGitter> <aboeglin> A::B.new ?
<z64> yes
<FromGitter> <j8r> Yes if you are outside, but inside `A` you can `B.new`
<FromGitter> <aboeglin> and what about just declaring the class as class A::B ?
<FromGitter> <j8r> like any defined class defined upper in the hierarchy in fact
<FromGitter> <aboeglin> and why not using a module for that ?
<FromGitter> <j8r> you can also, but here you may need instance variables
<FromGitter> <aboeglin> you mean B may use instance variables from A ? :o
marmotini_ has quit [Ping timeout: 250 seconds]
<FromGitter> <aboeglin> so you'd do instance_of_a::B.new ?
<FromGitter> <j8r> a purpose of this is when you want to use a class inside this class, you can `private class`
<FromGitter> <aboeglin> yes, obviously
<FromGitter> <aboeglin> you could also have two classes in a single file and one would be private right ?
<FromGitter> <aboeglin> and is it possible to define two sub classes in two different files ?
<FromGitter> <aboeglin> say B.cr: ⏎ ⏎ ```class A ⏎ class C ⏎ end ⏎ end``` [https://gitter.im/crystal-lang/crystal?at=5bc5e604ef4afc4f288245a8]
<FromGitter> <j8r> example: https://carc.in/#/r/591t
<FromGitter> <j8r> yes you can
<FromGitter> <j8r> this is called monkey patching: you reopen the module/class whatever to append defs
<FromGitter> <aboeglin> so I could take any class from the stdlib and just add a method to it like that ?
<FromGitter> <j8r> nvm hum not really monkey patching, because this is your app
<FromGitter> <j8r> yes this will be monkey path adding def/classes to the stdlib :)
<jokke> this: def foo(&block) .... foo(&bar.baz) doesn't seem to work. am i just using the wrong syntax or is this just not possible?
<FromGitter> <aboeglin> how would I go about importing it then ? I import both files in the source that should use the monkey patched class ?
<z64> @j8r yeah its less "patching" and just "reopening"
<FromGitter> <j8r> like https://carc.in/#/r/591x
<FromGitter> <j8r> :)
<jokke> so what i'm trying to do: instead of invoking a method on the block argument i want to invoke a method on another object and pass it the block argument(s)
<FromGitter> <aboeglin> wahh
<FromGitter> <aboeglin> it opens a whole new world ^^
<FromGitter> <j8r> haha, but better not to open this Pandora's box 😏
<FromGitter> <j8r> only when you really have to
<jokke> anyone?
<jokke> this is a pretty common use case.
<jokke> especially with things like `try` or `map`
<z64> jokke: i dont understand what you're trying to do, could you provide a full example
<jokke> so this is using router.cr
<z64> are you trying to pass the `.handle` function *as* the block? or whatever the `.handle` function returns?
<jokke> the former
<z64> i believe `->` is what you are looking for https://carc.in/#/r/5921
<jokke> that doesn't work if there's a dot
<jokke> also that's block capturing
<jokke> which isn't really fast
<jokke> or i mean.. not _as_ fast
<jokke> on the other hand the block is being captured by router.cr anyway
DTZUZU has joined #crystal-lang
<jokke> try adding params to bar
<z64> that isn't supported, no
<jokke> damn
<jokke> :(
<z64> i think to kind of do what you want, `.handle` would have to return a proc
<jokke> yeah
<jokke> (Handler is an alias to the Proc)
moei has quit [Ping timeout: 252 seconds]
moei has joined #crystal-lang
<FromGitter> <fusillicode_twitter> guys quick & stupid question: get all but the first element of an array? 🤔
<FromGitter> <fusillicode_twitter> I'm searching for `drop` but I can't find it
<FromGitter> <mamantoha> @fusillicode_twitter `array[1..-1]`
<FromGitter> <fusillicode_twitter> @mamantoha thanks a lot 🙇 let me play with it to see if it really fits my need :)
<FromGitter> <mamantoha> @fusillicode_twitter or `array.delete(1)` if you want to change original array
<FromGitter> <fusillicode_twitter> nono I prefer not to modify objects in place ;)
<FromGitter> <asterite> also: `array.skip(1)`
<FromGitter> <fusillicode_twitter> anyway [1..-1] give and index out of bound in case of empty array
<FromGitter> <fusillicode_twitter> @asterite thanks a lot 🙇 let me try it too :D
marmotini_ has joined #crystal-lang
<FromGitter> <Blacksmoke16> https://play.crystal-lang.org/#/r/58zs figured out a workaround for my annotation iterating
<FromGitter> <fusillicode_twitter> @asterite it seems that `skip` does exactly what I need, thanks really a lot for the support with such a stupid question 😓
<FromGitter> <asterite> I think we had `skip` and `drop` at one point, but because we don't want aliases... just note that right now `array[1..-1]` will probably be faster than `skip`, I'm writing a PR to fix that
<FromGitter> <j8r> or something like `array[1..-1]?`
DTZUZU has quit [Quit: WeeChat 2.2]
DTZUZU has joined #crystal-lang
<f1refly> Can someone here give me a hint how to create a File::Stat ? When i require "file" it doesn't find either "Stat" nor "File::Stat"
<f1refly> Never mind, i just found out that it was deprecated and replaced by File::Info
<FromGitter> <fusillicode_twitter> thanks once again for the broad explanation @asterite 🙇
<FromGitter> <michelson> Hoy can I initialize a NamedTuple from a Hash(k,v) ?
<FromGitter> <michelson> with JSON.parse I've receive a mixed type like `Hash{a: b , NamedTuple{c: b}}`
<FromGitter> <straight-shoota> @michelson `JSON.parse` can't possibly return a `NamedTuple` type
<FromGitter> <straight-shoota> Nonetheless, you can populate a `NamedTuple` from a `Hash` with `.from`: https://crystal-lang.org/api/0.26.1/NamedTuple.html#from%28hash%3AHash%29%3Aself-class-method
<FromGitter> <michelson> thanks @straight-shoota
<FromGitter> <michelson> I will look into that
rohitpaulk has joined #crystal-lang
<FromGitter> <michelson> it that NamedTuple needs to know the key values it will receive ?
<FromGitter> <michelson> how can I initialize it with a variable k , v ?
<FromGitter> <asterite> The answer is that you don't need NamedTuple. There's no use case for NamedTuple other than representing named arguments
rohitpaulk has quit [Ping timeout: 272 seconds]
<Yxhuvud> .. unless some API made by someone else requires them.
<FromGitter> <Blacksmoke16> i with you could splat annotations
<FromGitter> <michelson> I'm implementing a class with receives a hash option and I initializing some instance variables, here is the code ⏎ ⏎ ```code paste, see link``` ⏎ ⏎ error is in line 11:`instance variable '@options' of Command must be Hash(Symbol, String), not NamedTuple(message: String)` ... [https://gitter.im/crystal-lang/crystal?at=5bc60b511c100a4f2996da81]
<FromGitter> <michelson> now I'm just parsing JSON and .to_json to tackle this
<FromGitter> <michelson> but it does not feel right
<FromGitter> <Blacksmoke16> thats not a hash
<FromGitter> <Blacksmoke16> hash would be like `{:command => "one"}`
<FromGitter> <Blacksmoke16> https://play.crystal-lang.org/#/r/593i
<FromGitter> <Blacksmoke16> hence why you get the type mismatch error
<FromGitter> <asterite> @michelson you don't program like this in Crystal. Just pass arguments to the constructor
<FromGitter> <asterite> you can't initialize stuff from a Hash in Crystal
<FromGitter> <asterite> (unlike a dynamic language)
<FromGitter> <michelson> Hi Ary what you mean with just pass arguments to the constructor ?
<FromGitter> <michelson> `def initialize(command, target , options)` ?
<FromGitter> <asterite> Right, exactly. Now sure what "options" is used for, though
<FromGitter> <michelson> it is supposed to be a hash with variable key values
<FromGitter> <asterite> all of the same type? Say, string?
<FromGitter> <asterite> It should probably be "Hash(String, String)" then, if you plan to read that hash from a configuration or something (you can't create a Symbol dynamically)
<FromGitter> <michelson> I see. the way I've solve this was: ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5bc60ee6ef4afc4f28836d26]
<FromGitter> <asterite> but that `{} of Symbol => String` is kind of wrong...
<FromGitter> <michelson> its working aready. why is kinda wrong ?
<Yxhuvud> it's wasteful from a performance perspective
<FromGitter> <michelson> this `options = {} of Symbol => String` ?
<FromGitter> <michelson> I clearly beleive you, but I don't understand pretty well why
<FromGitter> <michelson> well , I've zero experience in this
<FromGitter> <michelson> haha
<FromGitter> <j8r> @michelson Because either you use a NamedTuple (which use symbols), or a `Hash(String, String)`. Symbol doesn't add anything here
rohitpaulk has joined #crystal-lang
<FromGitter> <asterite> that means a default value if you pass nothing
<FromGitter> <asterite> you clearly aren't passing nothing so it works
<FromGitter> <asterite> but if you pass nothing, you'll get an error
<FromGitter> <asterite> try it
wontruefree has joined #crystal-lang
non-aristotelian has joined #crystal-lang
<FromGitter> <bew> updating https://github.com/highlightjs/highlight.js/edit/master/src/languages/crystal.js : when was `type` a keyword?
<FromGitter> <bew> never seen it
<FromGitter> <bew> Ah shit
<FromGitter> <bew> Thanks
moei has quit [Quit: Leaving...]
wontruef_ has joined #crystal-lang
<FromGitter> <jwoertink> 😂
marmotini_ has quit [Ping timeout: 246 seconds]
wontruef_ has quit [Read error: Connection reset by peer]
wontruef_ has joined #crystal-lang
wontruefree has quit [Read error: Connection reset by peer]
marmotini_ has joined #crystal-lang
DTZUZU has quit [Quit: WeeChat 2.2]
DTZUZU has joined #crystal-lang
rohitpaulk has quit [Ping timeout: 246 seconds]
<FromGitter> <j8r> @asterite you have changed back your image from the Asterite to the Apple
moei has joined #crystal-lang
<jokke> i'm still experiencing this very weird bug where something with the socket of a http connection is going terribly wrong using traefik as a proxy
<jokke> the problem is: i can't really debug it since this is what i see on stdout: https://p.jokke.space/Iqur/
<jokke> even though i'm not compiling with --release
<jokke> might also be something related to docker swarm and the overlay network docker uses
<jokke> this reliably happens after the app has been running for a while
<jokke> i'm thinking that maybe traefik tries to keep the socket open indefinetely and at some point it just timeouts
<FromGitter> <Blacksmoke16> i was getting something similar iirc
<jokke> really?
<jokke> did you solve it somehow?
<FromGitter> <asterite> @j8r Yeah, I missed my original avatar...
<FromGitter> <Blacksmoke16> yea, is coming back to me
<jokke> you would make my day!
<FromGitter> <Blacksmoke16> issue was on a period task i had running using mosquito
<FromGitter> <Blacksmoke16> if it was long than x minutes between each it would throw an error like that
<FromGitter> <Blacksmoke16> solved it by calling `.close` on the HTTP::Client instance i had
<jokke> hmmmm
<FromGitter> <Blacksmoke16> as i think it was trying to keep it open for too long and it was timing out
<jokke> i have HTTP::Server though
<FromGitter> <Blacksmoke16> hm, could be realted?
<FromGitter> <aboeglin> Error writing to socket: Broken pipe
<FromGitter> <aboeglin> Do you get something like that ?
<jokke> yeah
<jokke> exactly that
<FromGitter> <aboeglin> It just seems I have it too
<FromGitter> <aboeglin> on swarm
<jokke> aha!
<FromGitter> <aboeglin> doesn't happen with docker-compose locally though
<jokke> yeah
<FromGitter> <aboeglin> but I use nginx as reverse proxy
<jokke> seems to be a swarm issue then
<jokke> i'm also not 100% sure _which_ socket this is but several things point to it not being http but rather postgres
<FromGitter> <aboeglin> well, I don't get that with other languages
<jokke> hm true
<FromGitter> <aboeglin> oh, you use postgres as well on that service ?
<jokke> yeah
<FromGitter> <aboeglin> haha
<FromGitter> <aboeglin> I do too ..
<jokke> we're getting closer
<jokke> because i have some routes that don't hit the db and those work fine
<jokke> also the db connection would be a long running connection
<FromGitter> <Blacksmoke16> is the container that hits the db on a diff service?
<jokke> not sure what you mean
<jokke> i have my crystal webapp as one service and postgres as another
<jokke> maybe it's just an issue of making the db shard more resistant against closed sockets
<FromGitter> <Blacksmoke16> yea could the issue be the swam timing out the connection between services
<jokke> yeah could be. but that'd be super annoying
<FromGitter> <Blacksmoke16> im not *super* familiar with swarm to know how to fix it, but why dont you have everything in the same service just diff containers?
<FromGitter> <Blacksmoke16> swarm has a notion of creating a service, and compose has its own notion of a service
<FromGitter> <Blacksmoke16> seems to be exactly your issue? :p
<jokke> yeahh
<jokke> i'll give it a try
<jokke> aboeglin: i'll report back in an hour if it's still working :)
<jokke> Blacksmoke16: thanks for helping with the debugging!
<FromGitter> <Blacksmoke16> np, hope you get it fixed
<jokke> yeah me too :)
<FromGitter> <aboeglin> Thanks, it would be great !
<FromGitter> <kingsleyh> how do I make an any type? would it be something like this? `alias Any = String|Nil|MyType` or like this `alias Any = Union(String,Nil,MyType)`
<FromGitter> <j8r> Yes @kingsleyh
<FromGitter> <kingsleyh> which one?
<FromGitter> <kingsleyh> this seems to work: ` alias Any = Union(RethinkDB::Cursor | RethinkDB::QueryResult | Array(RethinkDB::QueryResult) | Nil)`
<FromGitter> <Blacksmoke16> dont need the union, just `|` separated
DTZUZU has quit [Read error: Connection reset by peer]
<FromGitter> <aboeglin> Is your service still up ?
<FromGitter> <valamorgon> I've an array of hashes like this [{id=>1},{id=>2}] and I want to find a specific hash by using one of its attribute, like finding hash with id 1 in my example. Is there any way to achieve this without manually looping or changing structure of my array?
<FromGitter> <valamorgon> like find property of array in javascript
<FromGitter> <valamorgon> method*
<FromGitter> <aboeglin> Enumerable.find
<FromGitter> <aboeglin> It works exactly like in js with a block
<FromGitter> <valamorgon> @aboeglin I guess this is it, I will work on it, thanks
marmotini_ has quit [Ping timeout: 260 seconds]
marmotini_ has joined #crystal-lang
<FromGitter> <kingsleyh> how can I turn JSON::Any into a Hash of Symbol => valid Json type?
<FromGitter> <kingsleyh> it's easy to turn `{name: "kings"}.to_json` but I want to go the other way
<FromGitter> <kingsleyh> and start with `{"name "=> "kings"}.to_h` and get back the original hash map
<FromGitter> <kingsleyh> is there a library that does this or some built in thing that does this - or do I have to write my own Macro for this?
<FromGitter> <straight-shoota> A Hash of symbol keys is nothing you should ever do in Crystal.
<FromGitter> <straight-shoota> Just use string keys
<FromGitter> <straight-shoota> There is no benefit in using symbols, it's just more complicated
<FromGitter> <kingsleyh> ok - but how to get the JSON into the hash?
<FromGitter> <kingsleyh> do I have to write my own Macro? or is there something that will do it already?
<FromGitter> <straight-shoota> `any.as_h.transform_keys &.as_s` should to it.
<FromGitter> <kingsleyh> the keys are already strings
<FromGitter> <kingsleyh> any.as_h give me Hash(String, JSON::Any)
<FromGitter> <kingsleyh> so is there a transform_values
<FromGitter> <kingsleyh> any.as_h.transform_values(&.as_s) - but then all the values become strings
<FromGitter> <kingsleyh> so also not what I wanted - I would like the value to become the original type - e.g. Int32|String|anyother valid json type
DTZUZU has joined #crystal-lang
<FromGitter> <kingsleyh> I guess it’s impossible to know the type from the json
<FromGitter> <kingsleyh> As it’s JSON any
<FromGitter> <kingsleyh> I would have to keep a type mapping inside the json as well
<FromGitter> <kingsleyh> To know how to create the hash with the correct type
ashirase has quit [Ping timeout: 244 seconds]
<FromGitter> <girng> can try from_json: https://crystal-lang.org/api/0.26.1/JSON.html#mapping%28_properties_%2Cstrict%3Dfalse%29-macro
<FromGitter> <girng> you can specifically set the types if you know the json in advance
<FromGitter> <straight-shoota> Oh, yes you don't need to transform the keys for JSON. I was thinking about YAML::Any
<FromGitter> <straight-shoota> you can do `any.as_h.transform_values(&.raw)` to get the raw type (`JSON::Any::Type`). But it is generally better to keep it as `JSON::Any` for better accessibility
Heaven31415 has joined #crystal-lang
<Heaven31415> Hi
ashirase has joined #crystal-lang
marmotini_ has quit [Ping timeout: 244 seconds]
<FromGitter> <girng> Hi Heaven
<FromGitter> <ljuti> @straight-shoota You implemented a custom type `Value` for Crinja, right? Is the current implementation you have “complete”, in other words a working one?
<FromGitter> <ljuti> I tried to implement a similar custom type by using that as an example and it’s mostly working, but iterating over hash-like structures doesn’t work
<FromGitter> <ljuti> Maybe I missed something, and it’s best to rewrite it tomorrow with better spec coverage :)
<FromGitter> <straight-shoota> yep, it's currently pretty much complete
<FromGitter> <straight-shoota> at least considering what Crystal allows to do. I'd like to wrap any `Object`, really.
<FromGitter> <straight-shoota> It's pretty much the same concept as `JSON::Any` and `YAML::Any` btw
<FromGitter> <ljuti> My errors happen here https://github.com/straight-shoota/crinja/blob/master/src/runtime/value.cr#L54 (in my similar implementation)
<FromGitter> <ljuti> My `HashTupleIterator` returns custom tuples and those cannot be wrapped
<FromGitter> <ljuti> (If I’ve understood correctly what’s happening in that code)
<FromGitter> <straight-shoota> Yeah, the tuples must be a valid raw value type
<FromGitter> <ljuti> My data structure looks fine, I think
<FromGitter> <ljuti> ```code paste, see link```
<FromGitter> <ljuti> Ahh, the bug might be in my `Resolver`
wontruef_ has quit [Quit: bye]
<FromGitter> <ljuti> Yeah, one bug squashed :) Now I only need to fix the wrapping issue.
wontruefree has joined #crystal-lang
wontruefree has quit [Client Quit]
return0e has quit [Remote host closed the connection]
_whitelogger has joined #crystal-lang