Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • 08:50
    HertzDevil edited #11348
  • 08:34
    HertzDevil edited #11348
  • 08:33
    HertzDevil labeled #11349
  • 08:33
    HertzDevil opened #11349
  • 07:35
    HertzDevil opened #11348
  • 07:35
    HertzDevil labeled #11348
  • 07:35
    HertzDevil labeled #11348
  • 04:24
    HertzDevil synchronize #11139
  • Oct 22 19:53
    straight-shoota synchronize #11207
  • Oct 22 17:04
    straight-shoota synchronize #11139
  • Oct 22 17:04
    straight-shoota synchronize #11207
  • Oct 22 17:02
    straight-shoota synchronize #11297
  • Oct 22 17:02
    straight-shoota synchronize #11207
  • Oct 22 12:49
    straight-shoota closed #10889
  • Oct 22 12:49
    straight-shoota closed #6498
  • Oct 22 12:44
    straight-shoota closed #10377
  • Oct 22 12:43
    straight-shoota closed #11265
  • Oct 22 12:43
    straight-shoota closed #4704
  • Oct 22 12:43
    straight-shoota closed #11262
  • Oct 22 12:43
    straight-shoota closed #11253
<riza> the log context metadata does have the ability to inherit
From IRC (bridge bot)
@FromIRC
<riza> this test seems to point that you're right and things aren't getting inherited though https://github.com/crystal-lang/crystal/blob/dd40a2442fa186add8a82b74edb14a90aa1dae05/spec/std/log/context_spec.cr#L62-L78
<riza> if they were being inherited I'd expect there to be an assertion in here which proves that a == 1 too
George Dietrich
@Blacksmoke16
yea, makes sense
pretty sure there's a way to set the context on a fiber tho
From IRC (bridge bot)
@FromIRC
<riza> there is, for sure
<riza> Fiber#current_context= is available
<riza> sorry #logging_context=, not #current_context= https://github.com/crystal-lang/crystal/blob/master/src/log/metadata.cr#L222-L230
<riza> that's fine. I was hoping there was some magic which let log inherit instances of itself from the parent fiber
<riza> thanks :⁠)
From IRC (bridge bot)
@FromIRC
<riza> man, now my head is spinning. this looks right to me: https://carc.in/#/r/blh6
<riza> same result here: https://carc.in/#/r/blh8
<riza> man how is carc.in so fast when crystal play is so slow
George Dietrich
@Blacksmoke16
i think only metadata is serializable, not context
From IRC (bridge bot)
@FromIRC
* riza derp
<riza> this api is kind of confusing, because you call #set on the context but if you want to render all the things you've set you have to call context.metadata
George Dietrich
@Blacksmoke16
context represents global fiber data, while metadata represents data on a specific log message
mfiano
@mjfiano:matrix.org
[m]
    def unsafe_fetch(index : Int)
      raise "foo" if index != 0 && index != 1
      index.zero? ? x : y
    end

    def unsafe_fetch(index : Int)
      raise "foo" if index != 0 && index != 1
      case index
      when 0 then x
      when 1 then y
      end
    end
@Blacksmoke16 Curious if this is a bug, but the latter version results in a compiler error when using some Indexable methods: Error: no overload matches 'Array(Float64)#<<' with type (Float64 | Nil)
George Dietrich
@Blacksmoke16
unsafe_fetch can return nil
mfiano
@mjfiano:matrix.org
[m]
I mean it is still exhaustive i would think
George Dietrich
@Blacksmoke16
because thats the default return value of a case w/o an else
mfiano
@mjfiano:matrix.org
[m]
I would think it could either return x, y, or NoReturn
George Dietrich
@Blacksmoke16
which is why you need to put it in the else if you're using case
mfiano
@mjfiano:matrix.org
[m]
the raise catches not a 0 or 1, doesn't it?
George Dietrich
@Blacksmoke16
:shrug: guess it's not that smart?
mfiano
@mjfiano:matrix.org
[m]
Which has the special NoReturn type
mfiano
@mjfiano:matrix.org
[m]
What class does #[]= come from?
I would like to include the 5 overloads for #[]= of Array into my Indexable struct type. Any ideas?
mfiano
@mjfiano:matrix.org
[m]
Is there a better way to perform an element-wise operation on my Indexable struct?
    def round
      v = dup
      v.each_with_index { |elt, i| v[i] = elt.round }
      v
    end
From IRC (bridge bot)
@FromIRC
<riza> #map
mfiano
@mjfiano:matrix.org
[m]
But the point is to mutate while traversing
I don't see how to do that with map
From IRC (bridge bot)
@FromIRC
<riza> from your code there, I don't see what you're trying to achieve that map doesn't
mfiano
@mjfiano:matrix.org
[m]
map returns an iterator which can be converted to an array
in my code, i am mutating the ivars of an Indexable struct
Not constructing an intermediate sequence
From IRC (bridge bot)
@FromIRC
<riza> dup?
mfiano
@mjfiano:matrix.org
[m]
Yeah I'm doing it on a copy as a test to prevent some foot guns that were bothering me
From IRC (bridge bot)
@FromIRC
<riza> okay, I see. It looks like Indexable doesn't include map anyway
mfiano
@mjfiano:matrix.org
[m]
But self.each_with_index { |elt, i| self[i] = elt.round } doesn't return anything, unlike map
It modifies my struct in place
From IRC (bridge bot)
@FromIRC
<riza> sure, whats your end goal with this which each_with_index doesn't achieve?
mfiano
@mjfiano:matrix.org
[m]
each_with_index is what I came up with, and it works. I was only wondering if there was something more concise/more idiomatic for this use-case :)
I've only played with a tiny bit of the API, and no 3rd party libraries or anything yet
From IRC (bridge bot)
@FromIRC
<riza> dealing with the indices manually doesn't feel idiomatic to me, but it's not at all wrong
<riza> (I would run a .map so I didn't need to deal with the indices)
<riza> self.map {|e| e.round}