Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • 19:46
    wolfgang371 labeled #11342
  • 19:46
    wolfgang371 opened #11342
  • 14:02
    straight-shoota milestoned #11326
  • 13:58
    straight-shoota closed #11338
  • 13:58
    straight-shoota closed #11323
  • 13:18
    asterite closed #11341
  • 13:01
    beta-ziliani milestoned #11302
  • 10:53
    straight-shoota labeled #11335
  • 10:53
    straight-shoota labeled #11335
  • 10:53
    straight-shoota labeled #11335
  • 10:53
    straight-shoota labeled #11335
  • 10:53
    straight-shoota unlabeled #11335
  • 09:16
    straight-shoota labeled #11341
  • 09:16
    straight-shoota unlabeled #11341
  • 09:16
    straight-shoota labeled #11341
  • 09:16
    straight-shoota labeled #11341
  • 09:16
    straight-shoota unlabeled #11341
  • 07:26
    syalon labeled #11341
  • 07:26
    syalon opened #11341
  • Oct 19 18:53
    straight-shoota closed #11334
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}
mfiano
@mjfiano:matrix.org
[m]
that will produce an array, right?
From IRC (bridge bot)
@FromIRC
<riza> Well, #map isn't available on an Indexable so it wouldn't compile
<riza> what led you to use an Indexable instead of just an Array?
mfiano
@mjfiano:matrix.org
[m]
array is a generic class, not a module. Blacksmoke16 recommended me to include Indexable on my struct so that I can implement the abstract methods to be able to index/iterate over it
Which I have done and therefor get Enumerable and Iterable too
I'm not sure what you mean by #map not being available. It is inherited in Indexable from Enumerable
From IRC (bridge bot)
@FromIRC
<riza> oh I see, this is an exercise in implementing the modules
mfiano
@mjfiano:matrix.org
[m]
I mean what I have works. The map suggestion is only half of the work required.
From IRC (bridge bot)
@FromIRC
<riza> oh sure enough it is. I thought Indexable only included Iterable.
mfiano
@mjfiano:matrix.org
[m]
This is more than constructing a sequence of values. It is modifying the input sequence in the process, so does not need an intermediary sequence.
That's why I chose each_with_index. Maybe this is not idiomatic, but I don't see another way to do it efficiently
From IRC (bridge bot)
@FromIRC
<riza> you're probably right about that
<riza> a bunch of the crystal community sheds a lot of sweat about saving bits of memory... I try to avoid dealing with memory concerns
<riza> it's not wrong by any means, I'd just rather solve problems that aren't already more-or-less solved for me by the language
<riza> if that weren't the case, I'd write a lot more C
mfiano
@mjfiano:matrix.org
[m]
Usually a good decision, at least until profiling says you shouldn't
From IRC (bridge bot)
@FromIRC
<riza> yep, exactly
mfiano
@mjfiano:matrix.org
[m]
Ok thanks for the help :)
From IRC (bridge bot)
@FromIRC
<riza> thankfully in Crystal, it's pretty uncommon to need to care about an extra loop or copy of the data
mfiano
@mjfiano:matrix.org
[m]
Speaking of the Crystal community. It is small, but probably the most helpful for a newcomer than any of the few dozen languages I've used.
Very friendly crowd around here