<devil_tux>
basically, create new pointer with object from previous child and work upon it, inside the each I redeclare tmp_doc and push tmp_child to it
<devil_tux>
might be a bit unsafe tho' :> haven't tried slices yet
<devil_tux>
btw im not sure content would be appropriate here .. mind sharing a snippet?
laaron has quit [Remote host closed the connection]
<devil_tux>
let me create a skeleton
laaron has joined #crystal-lang
<FromGitter>
<codenoid> i'm back lmao
<FromGitter>
<codenoid> after long vacation
<FromGitter>
<HarrisonB> Is there a way to restrict a generic type, similar to how one would do it in java? (`T extends Foo`)
<devil_tux>
in short, recursive xml node children rebuilder on struct avoiding complete overwrite yielding array of string w/ value document content .. uh, not even kidding ..
laaron has quit [Remote host closed the connection]
<fullforce>
args is supposed to be a hash that I want to pass on to the function
<fullforce>
apologies for the bad wording
<crystal-lang564>
how does the function look like. Please show me the first line
<fullforce>
def test2(args : EventHolster)
<fullforce>
alias EventHolster = Hash(String, Int32 | String | EventHolster)
<fullforce>
crystal-lang564:
<crystal-lang564>
if you call that function then it must match. I'm new to crystal and had similar problems but could solve them after having a close look to the error message
<fullforce>
ah I see now
laaron has quit [Remote host closed the connection]
laaron has joined #crystal-lang
<fullforce>
is there a way I can make the overload accept different types?
<fullforce>
tried to cast Hash(String, String) to a Hash(String, Int32|String)
laaron has quit [Remote host closed the connection]
<crystal-lang564>
maybe you write functions with different signatures. The compiler will use then that function that match.
<fullforce>
can you elaborate on that please
<crystal-lang564>
crystal play is a good help
<fullforce>
what do you mean by diffent signatures
laaron has joined #crystal-lang
laaron has quit [Remote host closed the connection]
laaron has quit [Remote host closed the connection]
laaron has joined #crystal-lang
za1b1tsu has joined #crystal-lang
laaron has quit [Remote host closed the connection]
laaron has joined #crystal-lang
laaron has quit [Remote host closed the connection]
<FromGitter>
<yxhuvud> fullforce: `String` and `String|Int32` have a different size in memory, so they can't be casted directly.
<FromGitter>
<bew> @HarrisonB not yet #3298
laaron has joined #crystal-lang
laaron has quit [Remote host closed the connection]
laaron has joined #crystal-lang
laaron has quit [Ping timeout: 256 seconds]
<FromGitter>
<ditsara> quick question - does Crystal have a relatively uniform way to check for empty objects? for instance `#present?` and `#presence` in Rails
<FromGitter>
<yxhuvud> `present?` doesn't only check for emptyness, it also checks for not being nil etc. a variable that is nil is totally separate from if it is empty.
laaron has joined #crystal-lang
laaron has quit [Client Quit]
<FromGitter>
<ditsara> yes that's what I meant -- a check for nil, empty, whitespace only in a string, etc
laaron has joined #crystal-lang
<FromGitter>
<bararchy> `"string".nil?` will check for nil
<FromGitter>
<bararchy> `["a"].empty?` will check if it's empty
<FromGitter>
<bararchy> and `[nil, "a", nil].compact` will clear all `nil` values in the array for example
<FromGitter>
<bararchy> hope it helps
<FromGitter>
<ditsara> thanks ... it sort of helps i guess
<FromGitter>
<bararchy> that's the only way I can think of doing similar logic
<FromGitter>
<ditsara> yeah that's the same logic, just a bit more verbose
<FromGitter>
<bararchy> @straight-shoota It's just a VERY ruby thing to do, automagiclly get rid of Nils or unexpected input, while the right way would be to make a more restrictive checking and validation
<FromGitter>
<straight-shoota> IMHO it doesn't make much sense to combine the meaning of `nil` and an "empty" value
<FromGitter>
<straight-shoota> Especially in Crystal where we have static nil checks
<FromGitter>
<bararchy> ^ agree
<FromGitter>
<straight-shoota> But also in Ruby it stinks. If `nil` and `""` mean the same thing, there should only be one of them.
<jokke>
has anyone here worked with webrtc? is there a way to send broadcasts or do any type of peer discovery?
<jokke>
yxhuvud: `"foo".try(&.size.> 0)` would work as a sort of `present` for strings
<jokke>
Yxhuvud: since crystal supports re-opening classes you could also write a shard for this
<FromGitter>
<yxhuvud> @straight-shoota I think `present?` make sense in a rails context when handling different inputs, but as a general language feature it doesn't make sense
<FromGitter>
<ditsara> @yxhuvud yeah I agree it's most useful in a web app (or general input handling) context. i guess it wouldn't be too hard to write a shard for this that monkey patches Object, String, etc.
<FromGitter>
<straight-shoota> Yeah, maybe. But even there it should only be used once for mapping input to internal representation. There is no need to have this everywhere in your business logic.
<FromGitter>
<ditsara> > it should only be used once for mapping input to internal representation ⏎ yeah that's pretty much the use case -- processing user input
<FromGitter>
<Blacksmoke16> yea i see that now, just didnt because of the typeof
<FromGitter>
<j8r> thats like `typeof(raise "")`
<FromGitter>
<j8r> I posted in the @Blacksmoke16 issue
rohitpaulk has joined #crystal-lang
<Yxhuvud>
@j8r: I think you should create a new issue for the not suggestion rather reuse one that is about the error message, which frankly, your suggestion is totally orthogonal to
faitswulff has quit [Remote host closed the connection]
faitswulff has joined #crystal-lang
lvmbdv has quit [Ping timeout: 240 seconds]
lvmbdv has joined #crystal-lang
rohitpaulk has quit [Remote host closed the connection]
<fullforce>
trying to cast a Hash(String, String) to a Hash(String, String|Int32) overload
<fullforce>
is this possible?
<FromGitter>
<Blacksmoke16> so creating a method overload with that extra union, or convert an existing hash to make it compatible with that union?
<fullforce>
creating a method overload with that extra unin
<fullforce>
*union
<FromGitter>
<kinxer> @fullforce Could you make an example on carc.in?
<fullforce>
sure
<FromGitter>
<Blacksmoke16> that would be best yea
<FromGitter>
<kinxer> Trading in messy for (probably) slow, but that's a solution.
<fullforce>
hmm
<FromGitter>
<Blacksmoke16> kinda annoying you have a type restriction for `Int32 | String` yet it isnt that
<fullforce>
hmm
<fullforce>
whoops hit enter again sorry
<fullforce>
I want to be able to accept both int32 and string avlues
<fullforce>
*values
ternarysolo has joined #crystal-lang
<FromGitter>
<kinxer> @Blacksmoke16 Isn't there something different between method type restrictions and type checking elsewhere? I think I remember Asterite saying something about that in all the discussions about generics and type-checking.
<FromGitter>
<Blacksmoke16> might be easier to use a struct?
<FromGitter>
<Blacksmoke16> but depends on the full context of what hes trying to do
<FromGitter>
<Blacksmoke16> i.e. dynamic keys
<FromGitter>
<Blacksmoke16> where data is coming from et
<FromGitter>
<kinxer> You can't have an arbitrarily large number of keys and values with a struct.
<fullforce>
synamic keys yes
<fullforce>
*dynamic
<FromGitter>
<Blacksmoke16> in reality this is only going to be a problem when there is only a single type in your hash
laaron has quit [Remote host closed the connection]
scott_tams has quit [Remote host closed the connection]
ternarysolo has joined #crystal-lang
oprypin has quit [Quit: No Ping reply in 180 seconds.]
faitswulff has quit [Remote host closed the connection]
<FromGitter>
<bew> I'm wondering.... why does this work? (from your example @kinxer) Why the Hash passed the restriction against `EventHolster` ??
ternarysolo has quit [Ping timeout: 245 seconds]
faitswulff has joined #crystal-lang
faitswulff has quit [Remote host closed the connection]
<FromGitter>
<kinxer> My guess is that there's a difference between the explicit check in the method definition and the check against `Proc(T*, R)#call(*args : *T)`.
faitswulff has joined #crystal-lang
<FromGitter>
<kinxer> So the check in the generic method isn't as flexible as the check in the explicit method.
<FromGitter>
<kinxer> But I don't have enough knowledge about Crystals guts to know why that would be.
<FromGitter>
<bew> Basically the check in the method definition is a type restriction, but the problem I see is that the given args's type is `Hash(String, String)`, which shouldn't match the restriction with is `Hash(String, Int32 | String)` IMO.. (If we follow crystal's type system)
<FromGitter>
<kinxer> Yeah, I definitely see the weirdness there. I didn't think generics were flexible enough to do that yet (but this didn't occur to me when I wrote the code that works...).
<FromGitter>
<bew> ^^
faitswulff has quit [Remote host closed the connection]
faitswulff has joined #crystal-lang
faitswulff has quit [Remote host closed the connection]
faitswulff has joined #crystal-lang
faitswulff has quit [Ping timeout: 252 seconds]
gangstacat has quit [Ping timeout: 244 seconds]
faitswulff has joined #crystal-lang
return0e_ has quit [Ping timeout: 252 seconds]
return0e has joined #crystal-lang
gangstacat has joined #crystal-lang
DTZUZO has quit [Ping timeout: 255 seconds]
faitswulff has quit []
<FromGitter>
<MineraftSteve> Hi, I have a problem with reading a file in crystal
<FromGitter>
<MineraftSteve> I'm using the windows bash subsystem with debian, idk if thats the problem
<FromGitter>
<MineraftSteve> but, I have a file with just 'puts File.read("a")'
<FromGitter>
<MineraftSteve> and I compile it, and execute it, and while there is 100% a file named a in the same path, it prints this: "Unhandled exception: Error opening file 'a' with mode 'r': No such file or directory (Errno)"
<FromGitter>
<bew> Try `File.exists? "a"` to see if it detects it
<FromGitter>
<bew> also check `Dir.current` to make sure you're at the right place
<FromGitter>
<MineraftSteve> what's even weirder, is that if I run "crystal eval 'puts File.read("a")'" it prints out the file contents
<FromGitter>
<MineraftSteve> okay
<FromGitter>
<MineraftSteve> hmm
<FromGitter>
<MineraftSteve> the path I get is "/mnt/c/Users/(my user name)/Documents/project"
<FromGitter>
<MineraftSteve> even though the executable is in "/mnt/c/Users/(my user name)/Documents/project/src"
<FromGitter>
<MineraftSteve> if I run 'puts File.read("src/a")' it works
<FromGitter>
<bew> how are you running it?
<FromGitter>
<bew> (the executable)
<FromGitter>
<MineraftSteve> how do I get it to read files at the executable's path?
<FromGitter>
<MineraftSteve> ./src/out
<FromGitter>
<bew> yeah that's why
<FromGitter>
<MineraftSteve> ?
<FromGitter>
<bew> basically your program runs where you are, it doesn't matter where the binary is really located
<FromGitter>
<MineraftSteve> oh
<FromGitter>
<MineraftSteve> lol okay
<FromGitter>
<MineraftSteve> thanks
<FromGitter>
<bew> think about `ls`, the binary is somewhere in `/usr/bin`
<FromGitter>
<bew> but when you run `ls` you get the files in your current directory
<FromGitter>
<bew> not the files in `/usr/bin/`
<FromGitter>
<bew> you can do `which ls` to see where is `ls` if you want to check yourself
<FromGitter>
<MineraftSteve> yeah, okay
<FromGitter>
<MineraftSteve> that makes since lol
<FromGitter>
<MineraftSteve> thanks for the hel
<FromGitter>
<MineraftSteve> p
<FromGitter>
<bew> ;)
moei has quit [Quit: Leaving...]
ternarysolo has joined #crystal-lang
ternarysolo has quit [Ping timeout: 246 seconds]
devil_tux has quit [Ping timeout: 245 seconds]
<FromGitter>
<epoch> hello
<FromGitter>
<bew> hi!
<FromGitter>
<epoch> hi @bew
<FromGitter>
<epoch> just notice enum doesn't implement enumerable
<FromGitter>
<epoch> just wondering if you or anyone know the reason for that
<FromGitter>
<bew> Well an enum in crystal is just a value, you can't iterate on it
<FromGitter>
<Blacksmoke16> ^
<FromGitter>
<Blacksmoke16> can call `#names` or `#values` and iterate over those
<FromGitter>
<epoch> .each is implemented though
<FromGitter>
<epoch> I mean the whole set
<FromGitter>
<bew> oh on the enum type, not a specific instance.. We don't (can't ?) do that on types, only on instances for example for containers
<FromGitter>
<bew> what are you trying to do with your enum?
<FromGitter>
<epoch> I want to loop over that the set
<FromGitter>
<epoch> I see .each is implemented, having map and reduce as well would be nice
<FromGitter>
<bew> you can implement them yourself if you need them
<FromGitter>
<bew> I could see a use for map, but reduce....
<FromGitter>
<bew> AAAND as @Blacksmoke16 mentioned, you can do `YourEnum.values.map blablabla`