<FromGitter>
<HertzDevil> and if `+(other)` (no restriction) exists, currently that's stricter than the overload above so `+(other : BigFloatR)` needs to be written out too
<FromGitter>
<HertzDevil> mutating variants don't help much since the rounding mode is still there
alexherbo2 has joined #crystal-lang
richbridger has joined #crystal-lang
<FromGitter>
<lodenos> Hello guyβs, Iβve a question, how can we make a singleton class ?
<FromGitter>
<naqvis> make constructor private
<FromGitter>
<naqvis> create a class level variable and assign instance to that
<FromGitter>
<naqvis> create a static method which will return that instance
<FromGitter>
<Blacksmoke16> whats the end goal here?
<FromGitter>
<Blacksmoke16> looks right
<FromGitter>
<Daniel-Worrall> `ensure` ensures the code is read regardless of what happens, whether successful, unsuccesful, or errors
<FromGitter>
<Daniel-Worrall> s/read/run
<FromGitter>
<Daniel-Worrall> Not coding atm, but a thought came up. Does JSON::Serializable have a native way to store as String and parse data lazily as it's accessed?
<FromGitter>
<Daniel-Worrall> though I doubt converters are that expensive
<FromGitter>
<Blacksmoke16> i doubt it, as it uses a pull parser, so it couldnt just stop and wait before continuing as it couldnt parse anything else
<FromGitter>
<Daniel-Worrall> I mean like pulling it in as a string, then only converting it on an accessor or something
<FromGitter>
<Blacksmoke16> e.g. for a like nested obj or something?
<FromGitter>
<Daniel-Worrall> It could easily support a nested object, sure, but I didn't have it in mind
<FromGitter>
<Blacksmoke16> would still need to store the string, unless the data is really big i doubt it would have an affect
<FromGitter>
<Daniel-Worrall> This was prompted from the Time::Span regex from yesterday in the discord
<FromGitter>
<Daniel-Worrall> Yeah, but then you'd have no overhead from parsing
<FromGitter>
<Blacksmoke16> technically theres like no overhead for converters as they're usually class methods on a module, so dont even need to instantiate them
<FromGitter>
<Daniel-Worrall> there's the computation time?
<FromGitter>
<Blacksmoke16> prob not much more than you'd need to parse it as a raw string
<FromGitter>
<Daniel-Worrall> hmmm
<FromGitter>
<Blacksmoke16> maybe benchmark it?
<FromGitter>
<Daniel-Worrall> Idk what kind of objects would be computationally parse heavy, but you're right, it's something that needs to be benchmarked to gleam insight
<FromGitter>
<Blacksmoke16> it doesnt like large unions
<FromGitter>
<Blacksmoke16> as it essentially tries to parse it for each member
<FromGitter>
<Blacksmoke16> which raises an exception on each failure until it finds one that works
<FromGitter>
<Daniel-Worrall> oof
<FromGitter>
<Blacksmoke16> but thats not a real common use case imo
<FromGitter>
<Daniel-Worrall> Is there an Ordering you can provide if you know which objects are most common?
<FromGitter>
<HertzDevil> no
<FromGitter>
<HertzDevil> it's always alphabetical order since crystal internally canonicalizes all unions like that
<FromGitter>
<Daniel-Worrall> makes sense
<FromGitter>
<HertzDevil> which is reflected in `TypeNode#union_types`
<FromGitter>
<Daniel-Worrall> Maybe you could provide an option ordering
<FromGitter>
<Daniel-Worrall> optional
<FromGitter>
<HertzDevil> just write your own converter at that point
<FromGitter>
<Daniel-Worrall> Ahh
<FromGitter>
<HertzDevil> the default impl is in `json/from_json.cr`
<FromGitter>
<Daniel-Worrall> How can I sort by multiple parameters at once? Like i want to sort_by(&.property_one) and if they're equal sort_by(&property_two) without iterating multiple times. Iterator maybe?
<FromGitter>
<Blacksmoke16> `include Comparable(self)` and define `<=>`
<FromGitter>
<tenebrousedge> there's a sorting method that takes a block, yeah?