Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • 06:23
    matthewmcgarvey labeled #12831
  • 06:23
    matthewmcgarvey opened #12831
  • 00:44
    straight-shoota unlabeled #11647
  • 00:43
    straight-shoota milestoned #11647
  • 00:43
    straight-shoota milestoned #11647
  • 00:24
    straight-shoota assigned #12534
  • Dec 09 18:24
    Blacksmoke16 labeled #12830
  • Dec 09 18:16
    FnControlOption labeled #12830
  • Dec 09 18:16
    FnControlOption opened #12830
  • Dec 09 14:39
    Blacksmoke16 synchronize #10648
  • Dec 09 12:23
    straight-shoota assigned #12740
  • Dec 09 12:23
    straight-shoota synchronize #12740
  • Dec 09 11:28
    straight-shoota closed #11409
  • Dec 09 11:28
    straight-shoota labeled #11409
  • Dec 09 11:28
    straight-shoota labeled #11409
  • Dec 09 11:25
    straight-shoota labeled #12829
  • Dec 09 11:25
    straight-shoota labeled #12829
  • Dec 09 11:25
    straight-shoota closed #7532
  • Dec 09 11:24
    straight-shoota labeled #7532
  • Dec 09 11:24
    straight-shoota labeled #7532
azurelmao
@azurelmao
I see
George Dietrich
@Blacksmoke16
unless you make everything nilable and do something like:
foo = Foo.new
foo.id = 1
...
but ofc, having a proper constructor is usually the better way
i.e. Foo.new 1 or Foo.new id: 1
azurelmao
@azurelmao
I usually avoid Nilable types, because of the trouble they cause
Anyways, thank you for helping me!
George Dietrich
@Blacksmoke16
np
From IRC (bridge bot)
@FromIRC
<SamantazFox> For anyone interested: I've been doing my Advent of Code in Crystal this year ^^ https://github.com/SamantazFox/AoC-2022
From IRC (bridge bot)
@FromIRC
<riza> SamantazFox: there are a bunch of us, the Discord server has an aoc channel. But I'm over here at github.com/robacarp/advent_of_code/
<riza> a couple more links from the discord https://github.com/hovsater/aoc-crystal
<riza> there are probably many others
<riza> oh we have a leaderboard too....uuuummm
re:fi.64 🏳️‍🌈
@refi64:linuxcafe.chat
[m]
Note that mine is not actually in Crystal 😅
From IRC (bridge bot)
@FromIRC
<riza> oh whoops
<riza> i like that they're on sr.ht
<riza> i keep meaning to set up a gittea or something but ...
re:fi.64 🏳️‍🌈
@refi64:linuxcafe.chat
[m]
sr.ht is definitely pretty nice
Hasnep
@hasnep:matrix.org
[m]
Hi, does anyone know if there's a shard or some stdlib functionality to replicate Python's pydantic library? i.e. parsing JSON to a class
Hasnep
@hasnep:matrix.org
[m]
Perfect, thanks!
Maurizio De Santis
@mdesantis
hello! I'm confused by type aliases. I can't see why this works:
alias DeviceName = String
alias DeviceFile = Int32
alias DeviceDir = Hash(DeviceName, DeviceFile | DeviceDir)

pp Hash(DeviceName, DeviceDir).new
pp Hash(DeviceName, DeviceFile).new
#=> {}
#=> {}
but this doesn't:
alias DeviceName = String
alias DeviceFile = Int32
alias DeviceDir = Hash(DeviceName, DeviceFile | DeviceDir)

pp Hash(DeviceName, DeviceDir).new
pp Hash(DeviceName, DeviceFile).new
pp DeviceDir.new
#=>  21 | pp DeviceDir.new
#=>                    ^--
#=> Error: undefined method 'new' for DeviceDir.class
if DeviceDir is an alias of Hash(DeviceName, DeviceFile | DeviceDir), why can't I call .new on it?
ShalokShalom
@ShalokShalom
hi there
is there somebody who has tried to run Crystal on the GraalVM?
It has support
George Dietrich
@Blacksmoke16

related: crystal-lang/crystal#5155

recursive aliases are usually frowned upon, so might want to go to plan b

1 reply
Sean Gregory
@skinnyjames

Hi all, does anyone know of a good way to type an array of generic classes which is populated with an instance method using (forall)?
context here: https://play.crystal-lang.org/#/r/e7ts

Bonus: i was mucking around and did a bad here: https://play.crystal-lang.org/#/r/e7tt

Ali Naqvi
@naqvis

Hi all, does anyone know of a good way to type an array of generic classes which is populated with an instance method using (forall)?
context here: https://play.crystal-lang.org/#/r/e7ts

https://play.crystal-lang.org/#/r/e7ug

but such approach is quite fragile
also in your class you have restricted the types which Options array can hold, but add method isn't imposing any restriction, so it might break for cases where you call add with type which isn't part of your expected types.
Ali Naqvi
@naqvis

https://play.crystal-lang.org/#/r/e7ul

this snippet contains a macro check for add method and ensure only allowed types are allowed at compile time. So if you try invoking add method with Types which aren't part of Type alias, it will fail to compile.

e.g. invoking add with Int64 will raise compile time error.

https://play.crystal-lang.org/#/r/e7um

Sean Gregory
@skinnyjames

Ah, thanks.

also in your class you have restricted the types which Options array can hold, but add method isn't imposing any restriction, so it might break for cases where you call add with type which isn't part of your expected types.

Good call, I'd actually be fine without such restriction; just an array of OptionBuilder(T). I'd like to use the type to cast string values to (T), but probably not the best idea: https://play.crystal-lang.org/#/r/e7uu

George Dietrich
@Blacksmoke16
are a few CLI shards out there if that would be easier than rolling your own
Ali Naqvi
@naqvis

https://play.crystal-lang.org/#/r/e7uu

Compiler is right here, so you would have to perform checks before you can invoke methods on Union Type

https://play.crystal-lang.org/#/r/e7uw

Sean Gregory
@skinnyjames

are a few CLI shards out there if that would be easier than rolling your own

Ah yeah, I did take a look. I'll take another glance now that I have a better idea of what I'd like to do.

looking for something in particular?
Sean Gregory
@skinnyjames

looking for something in particular?
Was looking for something lightweight, extensible and up to date with latest Crystal.

I was looking into Admiral and Commander, but I think I'm going to poke around the docs for Athena console.
I want to attach a CLI to a task runner (base/abstract class), but also be able to compose (sub)commands in implementations of the task runner.

1 reply
George Dietrich
@Blacksmoke16
:thumbsup: sounds good. let me know if you have any questions about it.
most of the builders in that list mainly just focus on the arg/option parsing side of a CLI, athena's console component is more of a CLI framework in that it provides extra common utilities. Like for formatting/styling output, testing aids, creating tables, asking questions, etc
the one catch is it doesnt exactly support sub commands, but uses : as a way to group related commands. E.g. admin:create-user or admin:sync-data, etc
Sean Gregory
@skinnyjames
Nice, I'm a big fan of the TTY toolkit in ruby; haven't thought much about prompts etc.
George Dietrich
@Blacksmoke16
the question type docs would have more details of how they work. Or ofc easy enough to just play around with it