RX14 changed the topic of #crystal-lang to: The Crystal programming language | http://crystal-lang.org | Crystal 0.25.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
<crystal-gh> [crystal] faustinoaq opened pull request #6387: Fix missing comment inside code block example (master...patch-1) https://git.io/fNmpw
<crystal-gh> [crystal] faustinoaq opened pull request #6388: Fix udp example for udp method on Socket::Addrinfo (master...patch-2) https://git.io/fNmp1
<FromGitter> <talbergs> thanks Jarrod
khubo has quit [Ping timeout: 256 seconds]
khubo has joined #crystal-lang
moei has quit [Read error: Connection reset by peer]
moei has joined #crystal-lang
FromGitter has quit [Remote host closed the connection]
FromGitter has joined #crystal-lang
alex``` has quit [Quit: WeeChat 2.1]
akaiiro has joined #crystal-lang
DTZUZO has joined #crystal-lang
akaiiro has quit [Ping timeout: 260 seconds]
<FromGitter> <sam0x17> does anyone know where I can find the source code for crystal's error printing code? want to replicate exactly
<FromGitter> <sam0x17> found it myself: `ex.inspect_with_backtrace(STDERR)` does what I need
akaiiro has joined #crystal-lang
rohitpaulk has joined #crystal-lang
rohitpaulk has quit [Ping timeout: 244 seconds]
ua has joined #crystal-lang
ua_ has quit [Ping timeout: 256 seconds]
rohitpaulk has joined #crystal-lang
akaiiro has quit [Remote host closed the connection]
bmcginty_ has quit [Ping timeout: 256 seconds]
bmcginty has joined #crystal-lang
rohitpaulk has quit [Ping timeout: 260 seconds]
rohitpaulk has joined #crystal-lang
Philpax_ has quit [Quit: Leaving]
renzhi has joined #crystal-lang
_whitelogger has joined #crystal-lang
<FromGitter> <soanvig> @bew It seems, that branch from PR (fixing scry to match Crystal v0.25.0) doesn't work (with Crystal v.0.25.1 at least). But @faustinoaq said, he is busy, but he will be working on that, so I will wait :)
Philpax has joined #crystal-lang
phvse has joined #crystal-lang
rohitpaulk has quit [Ping timeout: 244 seconds]
<FromGitter> <soanvig> I have a question. I've created getter of name `hash` in class. It has `String` type. ⏎ ⏎ Now, I get, that `.hash` has possible two types: `String` (which is my implementation) and `hash` (which is native implementation https://crystal-lang.org/api/0.25.1/Object.html#hash-instance-method)
<FromGitter> <soanvig> I believe it's not correct behaviour, and because of that my code does not compile.
<oprypin> soanvig, ok so maybe don't do that?
<oprypin> it doesnt have 2 possible types, it has 1 which breaks the fundamentals of the language
<FromGitter> <soanvig> So it is possible to overwrite native function, but typings break up then? That's huge flaw
<oprypin> that's ruby's heritage for ya
<FromGitter> <soanvig> So what's the point of overwriting then? To provide custom implementation of the same return type?
<oprypin> if you have class A with one field @a and you create two instances `A.new(a=5)` and `A.new(a=5)` and by default they will not be equal and have a different hash
<oprypin> if you want to use them in context of comparison, you must override those
<oprypin> simplest way being https://crystal-lang.org/api/0.25.1/Object.html#def_equals_and_hash%28%2Afields%29-macro
<oprypin> recommended: View source
<FromGitter> <soanvig> That makes better sense, since this is 'hash' method, which is quite crucial. But what another methods?
<oprypin> i dont understand
<FromGitter> <soanvig> I mean, that there is method like, I don't know, Array#clear, which according to docs returns nothing. Now I overwrite it with a method, that does the same, but returns the `self` array. Now I will get errors too.
<oprypin> maybe, maybe not
<oprypin> depends on how bad the cascade is
<FromGitter> <soanvig> Hm. So it seems, that thing is quite tricky, and it's best to avoid overwriting with changing typings
<oprypin> it's best to avoid overwriting
<oprypin> do you think a lot of good things would happen if you changed `clear` to instead double the number of items in the array while still returning nil ?
<oprypin> but, some methods explicitly say "please override me and return a value of this type", so you can do that
<FromGitter> <soanvig> Yes, clear was just "random" example.
<oprypin> but you're supposed to override it in a subclass
<oprypin> if you directly modify Array's clear method, that's bad. if you subclass and modify it - whatever floats your boat, it can work just fine
<FromGitter> <soanvig> @oprypin in case, that I still don't change return type *
<oprypin> it's just that the language has the assumption "hash must return int64" everywhere throughout standard library
<oprypin> soanvig, you can do whatever you want, because existing code doesnt already rely on it, only your new code
<FromGitter> <soanvig> Hm
<FromGitter> <soanvig> That makes better sense nolw
rohitpaulk has joined #crystal-lang
<oprypin> yeah sorry, i made too much focus on reopening classes, which you probably didnt even care about
<oprypin> like `class Array(T); def clear; end; end;` - you could do this theoretically
<FromGitter> <soanvig> To be honest, what I needed was sha256 hash, instead of UInt64 :P
<oprypin> define `sha256` method
FromGitter has quit [Read error: Connection reset by peer]
FromGitter has joined #crystal-lang
<oprypin> define `sha256` method
<FromGitter> <soanvig> Thanks
<FromGitter> <soanvig> So I've got another question. I have @a which has type of `CustomClass | Nil`, and I do: `@b = @a ? @a.method : ""`, and get that `NIl.method is undefined`. Isn't the compiler clever enough?
<FromGitter> <soanvig> (I have such problems, because I come from other typing environment, and may not understand some things :/)
<FromGitter> <soanvig> I've already found it and deleted old comments. I believe IRC didn't catch that
<FromGitter> <BlobCodes> How can I make a self.load function that triggers all self.waitforload do |something| ⏎ end ⏎ ⏎ I thought about making a loop, but I wanted to know if there´s a method that´s more efficient [https://gitter.im/crystal-lang/crystal?at=5b4b2a7c6534bc5d2e5d51bd]
fbu has joined #crystal-lang
rohitpaulk has quit [Ping timeout: 276 seconds]
fbu has quit [Quit: WeeChat 2.1]
<FromGitter> <kingsleyh> what was IO.select and where did it go? was it removed?
FromGitter has quit [Remote host closed the connection]
FromGitter has joined #crystal-lang
<oprypin> kingsleyh, it was removed cuz it's blocking. there's a toplevel nonblocking select i think
<oprypin> hm only Channel.select perhaps
<FromGitter> <kingsleyh> how would I update this example? https://github.com/datanoise/ssh2.cr/blob/master/examples/shell.cr
<oprypin> lol 3 years old code
<FromGitter> <kingsleyh> yeah - the exec example still works - but the shell one does not
<FromGitter> <kingsleyh> I want to make several ssh commands in one sessoin
<FromGitter> <kingsleyh> and the shell approach looked like it might work
<oprypin> i think you dont need any select, just spawn 2 fibers with loops to do both of those things separately
<FromGitter> <kingsleyh> so open an ssh connection then start that shell - and make all the commands - and pipe the result out to STDOUT now
<FromGitter> <kingsleyh> I'll try that after lunch
<FromGitter> <drum445> How do you declare a Date type for a class attr? I can only see Time
<FromGitter> <drum445> ```property due_date : Time```
<FromGitter> <drum445> Hi guys, why can't I parse this: https://play.crystal-lang.org/#/r/4ir8
<FromGitter> <jspillers> does shards log more verbose errors somewhere? I am trying to create a basic shard lib and have it be a dependency of another app... getting a `Error resolving...` message but no specific information about what might have gone wrong
<FromGitter> <kingsleyh> oprypin - this does not stop for gets and it runs and does nothing visible
<FromGitter> <kingsleyh> maybe I don't need 2 spawns
<FromGitter> <kingsleyh> I think it doesn't work with fibers
dragonkh has joined #crystal-lang
<FromGitter> <kingsleyh> hmm
dragonkh has quit [Client Quit]
<FromGitter> <BlobCodes> The fibers are only executed if the programm sleeps/yields.
<FromGitter> <BlobCodes> Maybe try yield after the spawns
<FromGitter> <kingsleyh> cant use yield outside of a method :(
pabs has quit [Ping timeout: 260 seconds]
<FromGitter> <BlobCodes> Why do you even need those fibers ?
pabs has joined #crystal-lang
<FromGitter> <kingsleyh> oprypin suggested - because IO.select is gone now
<FromGitter> <kingsleyh> trying to make this work: https://github.com/datanoise/ssh2.cr/blob/master/examples/shell.cr
<FromGitter> <BlobCodes> try Fiber.yield ?
<FromGitter> <kingsleyh> ok - now I get an error which is an improvement
<FromGitter> <kingsleyh> Index out of bounds (IndexError)
<FromGitter> <kingsleyh> something to do with this: print String.new buf[0, len]
<FromGitter> <kingsleyh> although it still did not stop at the gets
<FromGitter> <kingsleyh> I expected it would stop and let me type something at the gets
<FromGitter> <jspillers> im creating a shard and for some reason when adding it as a dependency i have to specify the branch name or it throws `Error resolving ta4cr (0.1.0)` when doing a `shards install` - i have compared the shards.yml to other libs and it doesn't appear i am missing anything there...
<FromGitter> <jspillers> ```dependencies: ⏎ ta4cr: ⏎ github: jspillers/ta4cr ⏎ version: ~> 0.1.0``` ⏎ ⏎ does not work [https://gitter.im/crystal-lang/crystal?at=5b4b637866c1e833a9eb5956]
Philpax has quit [Ping timeout: 240 seconds]
<FromGitter> <drum445> Some confusion over the Time type (as there doens't seem to be a data) When I do a .to_json on my class that contains a attr that is of type Time it is returning "2018-06-14T00:00:00Z" how can I make it only reutrn the date?
<FromGitter> <drum445> is there just a date type?
TCZ has joined #crystal-lang
TCZ has quit [Client Quit]
<FromGitter> <drum445> Why can't I loop through: "undefined method 'each' for JSON::Any"
<FromGitter> <Daniel-Worrall> you need to cast it as something first
<FromGitter> <Blacksmoke16> https://play.crystal-lang.org/#/r/4irr
<FromGitter> <Blacksmoke16> I feel like the to_json of that should be `"{\"latitude\":12.3,\"longitude\":34.5}"`, as the way i was thinking about it was the `@[JSON::Field(key: "lng")]` just determined the key from the JSON object to assign to that particular instance var
<FromGitter> <bew> I don't understand what you mean @Blacksmoke16
<FromGitter> <Blacksmoke16> see how the output is `"{\"lat\":12.3,\"lng\":34.5}"`?
<FromGitter> <Blacksmoke16> the properties name is defined as `longitude`
<FromGitter> <Blacksmoke16> `@[JSON::Field(key: "lng")]` should just allow you to specify a different key name (in this case `lng`) to assign to that var
<FromGitter> <Blacksmoke16> but its actually altering the key names when doing `to_json`
<FromGitter> <Blacksmoke16> https://play.crystal-lang.org/#/r/4irs maybe that makes it more clear?
<FromGitter> <Blacksmoke16> it could be desired behavior, just not how i was thinking it worked
alex`` has joined #crystal-lang
<FromGitter> <bew> Ah yeah it doesn't work like that! It changes the key for this property, for decoding & encoding of json
<mindcrimes> is there a way to get the name of a function?
<FromGitter> <bew> You can do `{{@def.name}}`
<FromGitter> <Blacksmoke16> is that the desired behavior?
<FromGitter> <Blacksmoke16> seems kinda strange imo
<FromGitter> <bew> Why strange?
<FromGitter> <Blacksmoke16> i just thought it allowed you to change they key that is used to assign to the given instance var
<FromGitter> <Blacksmoke16> not like override the whole key for decoding/encoding,
<FromGitter> <Grabli66> Hi! Why type is not (Int32 | String | Nil) ? https://play.crystal-lang.org/#/r/4isf
<FromGitter> <Blacksmoke16> 2nd include prob overrides the first
<FromGitter> <Blacksmoke16> https://play.crystal-lang.org/#/r/4isg
<FromGitter> <Grabli66> Ok
<FromGitter> <Blacksmoke16> as if i wanted to consume json `{"CamelCaseName": "value"}` and did like ⏎ ``` ⏎ @[JSON::Field(key: "CamelCaseName")]
<FromGitter> <Blacksmoke16> to me `camel_case_name` should equal "value" and output of to_json would be `{"camel_case_name": "value"}` but oh well
<crystal-gh> [crystal] sdogruyol closed pull request #6371: Add ECR.render for rendering without setting up an IO (master...jm/feature/ecr-render) https://git.io/fNLUc
<FromGitter> <bew> @Blacksmoke16 then how would you make a json like the original one?
<crystal-gh> [crystal] sdogruyol pushed 1 new commit to master: https://git.io/fNYW2
<crystal-gh> crystal/master 24b860e Faustino Aguilar: Fix udp example for udp method on Socket::Addrinfo (#6388)
<FromGitter> <Blacksmoke16> custom `to_json`
<FromGitter> <Blacksmoke16> to build out the object with the original keys
<FromGitter> <Blacksmoke16> but i guess it works in reverse, ill have to do that to get what i want from what the JSON supplies
<crystal-gh> [crystal] sdogruyol closed pull request #6336: Improve docs of big module overloads (master...laginha87-improve-big-docs) https://git.io/fbhC8
<FromGitter> <Blacksmoke16> `value_key` JSON::Field option would be cool, combine the parsing and transformation into one step
rohitpaulk has joined #crystal-lang
<travis-ci> crystal-lang/crystal#a2f4d61 (master - Add ECR.render for rendering without setting up an IO (#6371)): The build passed. https://travis-ci.org/crystal-lang/crystal/builds/404165510
<DeBot> https://github.com/crystal-lang/crystal/pull/6371 (Add ECR.render for rendering without setting up an IO)
rohitpaulk has quit [Ping timeout: 244 seconds]
<travis-ci> crystal-lang/crystal#3b3bf3f (master - Adds code samples on the big module to methods that are extending classes that are part of the standard library (#6336)): The build passed. https://travis-ci.org/crystal-lang/crystal/builds/404166174
<DeBot> https://github.com/crystal-lang/crystal/pull/6336 (Improve docs of big module overloads)
<FromGitter> <drum445> Hi, wondering if somebody could help me out. I have dates coming from mysql and being used in a class. ⏎ I want to return just the date via my api in JSON format.
<FromGitter> <drum445> The problem I am having is when I do the following: https://play.crystal-lang.org/#/r/4isn ⏎ It returns the full Time object instead of just the date. Any way around this please?
rohitpaulk has joined #crystal-lang
<FromGitter> <Blacksmoke16> https://play.crystal-lang.org/#/r/4ist ?
<FromGitter> <Blacksmoke16> if you dont need to full Time object you could also do like
<FromGitter> <drum445> Thanks @Blacksmoke16, I had something similar to that but the object I have has a lot of attr so makes it a bit messy. Maybe it's the only way
<FromGitter> <Blacksmoke16> https://play.crystal-lang.org/#/r/4isv
<FromGitter> <drum445> I started out as it being string, but it seems wrong to store a date in a string
<FromGitter> <drum445> you're probably right, falling into that trap of making things more difficult than need be lol
<FromGitter> <drum445> As long as it's a datetime in my db it shouldn't matter it being a string in code
<FromGitter> <Blacksmoke16> or is it even a problem that it returns full datetime?
<FromGitter> <drum445> not really, although the put request for Note would be nicer if you didn't have to supply full datetime
<FromGitter> <drum445> And having the response and the request format be diff is odd
<FromGitter> <Blacksmoke16> true
<FromGitter> <Blacksmoke16> guess depends on how you want it to be setup and what the user flow is
<FromGitter> <drum445> Indeed, will have a ponder. Cheers mate
<jokke> i noticed there are no universal conversion methods like in ruby Integer() or String() or whatever
<jokke> am i missing something?
<FromGitter> <Blacksmoke16> to do what? turn a string into an int?
<jokke> yeah but not just into an int
<FromGitter> <rishavs> Hi guys. How do I initialize a data structure like; ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5b4b8cdc95e03e3d7b4f0807]
<jokke> i want to write a macro which will receive a type as an argument and will use that to turn a string into whatever it got passed as type
<FromGitter> <Blacksmoke16> https://play.crystal-lang.org/#/r/4isz
<FromGitter> <rishavs> In js, creting nested jsons are very easy
<jokke> Blacksmoke16 sure :)
<jokke> but that would require me to know the type
<jokke> *for me
<FromGitter> <Blacksmoke16> ah i see
<jokke> basically i want to do this: {{type}}(string_value)
<jokke> i already tried just passing the string value to the constructor but that doesn't work for String - ironically
<jokke> hm maybe there's a from_string method
<jokke> nope
<jokke> i could do {{type}}.from_io(IO::Memory.new(string_value)) but it seems a bit overkill
<jokke> oh
<jokke> and it wouldn't work
<FromGitter> <j8r> I think you can use generics
<jokke> how?
<FromGitter> <j8r> But wait what types you want to turn to string?
<jokke> any
<jokke> no
<jokke> not to string
<jokke> _from_ string
<FromGitter> <j8r> and transform them to what? A class is a class
<jokke> to whatever i get passed as type
<FromGitter> <j8r> `to_s` don't fit?
<jokke> _from_ string
<jokke> not to
<FromGitter> <j8r> or ok. And from a given string, transform to what so :)?
<FromGitter> <drum445> I take donations through paypal ;)
<FromGitter> <straight-shoota> Apart from number types, there are not many conversions from string
<jokke> drum455 try with String ;)
<jokke> straight-shoota
<FromGitter> <straight-shoota> but when there is, `{{ type }}.new(string)` should work
<jokke> your right
<jokke> *you're right
<jokke> but it breaks for string
<jokke> which is pretty lame
<FromGitter> <straight-shoota> Why would you convert a String to a String??
<jokke> well... it's just a macro
<FromGitter> <straight-shoota> and?
<jokke> how should i know what get's passed to it
<FromGitter> <bew> And how would you build that type from the String? There is no generic way to build any types, unless you write it yourself.. Can you give examples?
<FromGitter> <straight-shoota> `unless string.is_a?(String)`
<jokke> ofc i can write an {% if type == String %} around it
<jokke> but that kinda sucks
<FromGitter> <drum445> why would you pass a string into it?
<jokke> :D
<jokke> because sometimes you want strings
<FromGitter> <drum445> but it's already a string
<jokke> D:
<jokke> but how should i know that?
<FromGitter> <drum445> check before calling it
<FromGitter> <bew> @rishavs it depends on the usecase, does the nested object change? Or it has always the same fields? Can you make a class for it?
<jokke> that totally defeats the purpose drum445
<jokke> i want something as universal as from_json
<FromGitter> <drum445> but from_json doesn't convert Strings to an arbitrary type
<jokke> i mean.. there's a to_i method for integers as well
<FromGitter> <drum445> how would it know what to convert it to
<FromGitter> <straight-shoota> sry
<jokke> i pass it to the macro
<jokke> that's how it knows
<FromGitter> <straight-shoota> `unless string.is_a?({{type}})`
<jokke> yeah
<FromGitter> <straight-shoota> if `string` already is a `type` there is no need to convert it
<jokke> i'll do it like that
<jokke> no
<jokke> i'll do it with {% if type == String %}
<FromGitter> <drum445> @jokke what is your use case?
<jokke> so it won't steal any cycles at runtime
<FromGitter> <bew> 👍
<FromGitter> <drum445> give us a playground example
<FromGitter> <drum445> If you are always passing in a string, why would you ever want to convert a str object?
<FromGitter> <rishavs> @bew the object is fairly dynamic and thats the major problem. I am trying to convert an array of hashes into a tree (for my comments system). When i did it in JS, I used this small piece of code; ⏎ ⏎ ```code paste, see link``` ⏎ ⏎ In crystal I can't proceed beyond the first line T_T [https://gitter.im/crystal-lang/crystal?at=5b4b91041c0f906b145782eb]
<FromGitter> <bew> Can you give examples input & output, see what we can do for it?
<FromGitter> <drum445> sounds like you might be best creating classes that have attributes of other classes if it's a nested json blob
<jokke> drum445 that's my usecase
<FromGitter> <drum445> ok and what would the call look like?
<FromGitter> <rishavs> The input is; ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5b4b928695e03e3d7b4f2239]
<FromGitter> <drum445> I struggle to understand how you would have a string object but know it should be an int
<FromGitter> <drum445> Surely if you knew it should be an int, it would just be an int
<jokke> drum445: like this: setting bind_port, Int32, 3000
<jokke> or setting bind_host, String, "localhost"
<FromGitter> <drum445> and how would you be in a situation where you knew what type the var should be but it was a string?
<FromGitter> <rishavs> whoops, i managed to delete all that.... ⏎ My input is ; ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5b4b939d866e0c6b15ac5a29]
<jokke> drum445 what do you mean?
<jokke> i just showed you an example of it being a string
<FromGitter> <drum445> but it's a hardcoded string
<jokke> what?
<jokke> did you look at the code at all?
<FromGitter> <drum445> I have no idea what you want the output of your macro to be
<FromGitter> <drum445> lol
<FromGitter> <drum445> So this for example ⏎ setting bind_port, Int32, 3000
<FromGitter> <drum445> 3000 is already an int
<FromGitter> <drum445> So how could your else in your macro ever manage an upcase?
<jokke> wut
<jokke> it upcases the name :D
<FromGitter> <drum445> Please explain what issue you are trying to solve
<jokke> ok let me play compiler
<jokke> setting bind_port, Int32, 3000 becomes:
<jokke> getter bind_port : Int32 = ENV["BIND_PORT"]?.try { |string_value| Int32.new(string_value } || 3000
<jokke> does that help?
<FromGitter> <drum445> not really
<jokke> :/
<FromGitter> <drum445> why can't you just bind_port in the normal way
<FromGitter> <drum445> What's with this strange call?
<jokke> what part of it is strange to you?
<FromGitter> <drum445> The problem you are trying to solve
<FromGitter> <drum445> You still haven't really told us what it is
<jokke> the class is called EnvConfig. what do you think?
<jokke> you have an app you can configure with env vars right?
<FromGitter> <drum445> well yes, but why aren't you just doing ⏎ ENV["BIND_PORT"] = 3000
<jokke> env var values are _always_ strings
<jokke> i want a typed config
<jokke> where numbers are actually represented as such
<FromGitter> <drum445> Yes, but even the docs say this: ⏎ https://crystal-lang.org/api/0.19.2/ENV.html
<jokke> sure
<jokke> that sucks though
<FromGitter> <drum445> what?
<FromGitter> <drum445> How is that not cleaner than a macro
<FromGitter> <drum445> You know port is always an int
<jokke> because let's say it's a config i use a lot
<FromGitter> <drum445> So what's the issue
<FromGitter> <drum445> ok, go on
<jokke> i pass it the key as string all over the place
<jokke> then i misspell it somewhere
<jokke> i only know about this at runtime
<jokke> this wont _ever_ happen with a macro like that
<FromGitter> <drum445> I feel like you're in a mindset where you are making something more complex than it needs. I often have this too
<FromGitter> <drum445> But if you just pass ```ENV["PORT"].to_i``` to w/e needs it
<FromGitter> <drum445> you're sorted
<FromGitter> <drum445> just don't spell PORT wrong, but that's the same as all Hash types
<jokke> also i don't have to spread around multiple to_something calls just because the value i'm using isn't a string
<FromGitter> <drum445> But you do have to call a macro
<jokke> that's why hash types are so inferior to actual classes with attributes
<jokke> or structs
<jokke> what's wrong with calling a macro??
<jokke> you do it all the time
<FromGitter> <drum445> well not inferior, just a different approach, they have their uses
<FromGitter> <drum445> Nothing is wrong with it mate, but there is also nothing wrong with to_i32
<FromGitter> <drum445> and I'd argue that to_i32 is a lot easier for a new dev to understand than having to decrypt a custom macro
<FromGitter> <drum445> Let me know what you settle on though
<jokke> 1. it's not DRY if you need it in many places in your application, 2. it's not typesafe since it's up to you to do the to_something, 3. it's very easy to misspell the key
<FromGitter> <drum445> I wouldn't say a cast is WET
<FromGitter> <drum445> I also would say that if you are that concerned with spelling your key wrong (for some reason) just to do a .includes?(key) before anything else
<jokke> sure is if you do it multiple times for the exact same value
<FromGitter> <drum445> write a helper method then
<jokke> lol
<FromGitter> <drum445> most useless helper I've ever seen though
<jokke> and you said the macro was too much? :D
<FromGitter> <drum445> exactly
<FromGitter> <drum445> also why are you passing the ENV vars around?
<jokke> have you ever worked with docker?
<FromGitter> <drum445> yer
<FromGitter> <drum445> Why do so many palces need the port
<jokke> dude... :D
<jokke> are you just trolling?
<FromGitter> <drum445> Ok I'm out, I still feel you're massively over complicating things. But I have better things to be doing
<jokke> lol
<FromGitter> <Blacksmoke16> couldn't you just make a class tha you pass all these ENV vars to, then assign an instance of that class to like `ENV_HELPER` variable in global namespace then reference that everywhere, where you only have to do the case once in the initialize method of the class?
<FromGitter> <drum445> indeed, but he is worried about misspelling the hash key...
<FromGitter> <Blacksmoke16> spell check?
<FromGitter> <drum445> tell me about it
<FromGitter> <Blacksmoke16> i get his point but i feel like that isnt a valid enough reason to make this more complex than a class and pass all env vars to
<FromGitter> <drum445> Agreed
<FromGitter> <Blacksmoke16> then can cast and assign each ENV value to its own instance variable
<FromGitter> <drum445> Just don't look at JS @jokke ;)
<FromGitter> <straight-shoota> jokke, you probably shouldn't have multiple places reading the same value from `ENV`
<jokke> exactly
<FromGitter> <straight-shoota> abstracting that in a helper method, config class or whatever is better
<jokke> which is exactly what i'm doing
<FromGitter> <drum445> You said I was trolling when I suggested something similar
<FromGitter> <straight-shoota> yeah, but you're likely overcomplicating it
<FromGitter> <drum445> So if ENV is just a hash, just have ⏎ ENV["PORT_INT"] = 5000
<jokke> it's hard for me to understand how a 4 line macro is overcomplicating things :D
<FromGitter> <drum445> if you really have to
<FromGitter> <drum445> compared to a 4 character cast it really is
<FromGitter> <straight-shoota> you don't need the macro at all :D
<FromGitter> <drum445> to_i
<FromGitter> <straight-shoota> `setting bind_port, Int32, 3000` can just be `getter bind_port { ENV.fetch("BIND_PORT", "3000").to_i }
<FromGitter> <rishavs> Any ideas how should I proceed ahead? :(
<jokke> straight-shoota: i will need macros if i want to be able to check at compile time if my accessing and passing settings to methods is typesafe and correct
<FromGitter> <drum445> Just have a helper, or a common class that holds the int
<FromGitter> <straight-shoota> I don't follow
<jokke> straight-shoota: of course, that's what i was going with before, until i realized that i have 15 of such lines
<FromGitter> <straight-shoota> so be it =)
<jokke> terrible
<FromGitter> <straight-shoota> abstracting this in a macro adds a lot of constraints
<FromGitter> <straight-shoota> you can't easily use custom string conversions
<FromGitter> <Blacksmoke16> https://play.crystal-lang.org/#/r/4ivt
<FromGitter> <straight-shoota> names of env var and property are strictly matching (with upcase)
<FromGitter> <drum445> +1 @Blacksmoke16
<FromGitter> <bew> @rishavs I'm making an eample for you :)
<FromGitter> <straight-shoota> I don't think there is anything wrong with having a couple of lines like this
<FromGitter> <Blacksmoke16> which will error if you give invalid type https://play.crystal-lang.org/#/r/4ivu
<FromGitter> <rishavs> @bew 😻
Yxhuvud has quit [Read error: Connection reset by peer]
Yxhuvud has joined #crystal-lang
rohitpaulk has quit [Ping timeout: 265 seconds]
<FromGitter> <bew> @rishavs here is an example, do whatever you want with it :D https://carc.in/#/r/4iwp
<FromGitter> <bew> note that it doesn't handle the case where parent_id doesn't exist
<FromGitter> <rishavs> Thanks @bew you are awesome!
<FromGitter> <bew> one tries 😄
<FromGitter> <rishavs> I need to unlearn so much about how I did things in JS. I would be totally lost without the amazing community in here.
<FromGitter> <rishavs> you guys rock! 👯
<FromGitter> <bew> yeah it's a big gap from a language like JS, but it can only make you better ;) we're happy to help
phvse has quit [Ping timeout: 260 seconds]
<FromGitter> <drum445> I feel my dev skills have improved quite a lot since learning Crystal
<FromGitter> <drum445> Not sure why but it makes you think about types a lot more
<FromGitter> <j8r> @drum445 handling types at compile makes a safer and more robust code :)
<FromGitter> <drum445> for sure, too many bad habits from years of Python lol. I always feel like it's a hack in dynamically typed
<FromGitter> <Daniel-Worrall> I feel like Char should have a `.*` for creating strings on a number of chars
<FromGitter> <Daniel-Worrall> `'a' * 5 # => "aaaaa"`
<FromGitter> <Daniel-Worrall> It's a thing for string
<FromGitter> <Daniel-Worrall> Either I should be casting it to a string, then doing it, or it should cast to string and do it
<FromGitter> <bew> there is nothing like "cast to string"
<FromGitter> <bew> is `'a'` in a variable? or is it your code?
<FromGitter> <bew> if it's your code, just use `"a" * 5`
<FromGitter> <Daniel-Worrall> My use case though is bad code ⏎ ⏎ ```string = "abcd" ⏎ repeat = string[0] * 5``` [https://gitter.im/crystal-lang/crystal?at=5b4bb2606534bc5d2e5f01f2]
<FromGitter> <Daniel-Worrall> I could also do `string[0,1]`
<FromGitter> <bew> what is it for?
<FromGitter> <Daniel-Worrall> I found out they have Crystal support
<FromGitter> <Daniel-Worrall> so I've been giving it a go
alex`` has quit [Quit: WeeChat 2.1]
fluff has joined #crystal-lang
fluff has quit [Client Quit]
_whitelogger has joined #crystal-lang
FromGitter has quit [Read error: Connection reset by peer]
FromGitter has joined #crystal-lang
FromGitter has quit [Read error: Connection reset by peer]
FromGitter has joined #crystal-lang
<FromGitter> <Daniel-Worrall> How can I group elements in an Array given that they're next to each other and satisfy a condition. ⏎ For example Array of Ints `[1, 2, 2, 3, 3, 2, 4]`, how could I group even numbers together to produce `[[1], [2, 2], [3], [3], [2, 4]]` or similar
<FromGitter> <Blacksmoke16> whats the condition
<FromGitter> <Daniel-Worrall> evens
<FromGitter> <bew> I don't think there is something builtin for that (I can be wrong), either do it yourself, or try to find something in https://crystal-lang.org/api/0.25.1/Enumerable.html or https://crystal-lang.org/api/0.25.1/Array.html
<FromGitter> <Daniel-Worrall> I've been looking, there's nothing built in
<FromGitter> <Blacksmoke16> then do it manually it is :p
<FromGitter> <Daniel-Worrall> https://carc.in/#/r/4iyd disgusting but works
<FromGitter> <bmulvihill> @Daniel-Worrall would chunks work for your problem? https://github.com/crystal-lang/crystal/blob/master/src/enumerable.cr#L83-L105