Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • 07:55
    Tamnac opened #13026
  • Jan 28 21:02
    Blacksmoke16 labeled #13025
  • Jan 28 21:02
    Blacksmoke16 labeled #13025
  • Jan 28 21:02
    Blacksmoke16 labeled #13024
  • Jan 28 21:02
    Blacksmoke16 labeled #13024
  • Jan 28 18:45
    asterite opened #13025
  • Jan 28 16:23
    meatball133 synchronize #13024
  • Jan 28 15:53
    meatball133 edited #13024
  • Jan 28 15:51
    meatball133 opened #13024
  • Jan 28 15:10
    meatball133 ready_for_review #13008
  • Jan 28 13:24
    straight-shoota closed #13014
  • Jan 28 02:34
    Blacksmoke16 labeled #13023
  • Jan 28 02:19
    cyangle labeled #13023
  • Jan 28 02:19
    cyangle opened #13023
  • Jan 28 00:41
    devnote-dev labeled #13022
  • Jan 28 00:41
    devnote-dev opened #13022
  • Jan 27 23:05
    straight-shoota labeled #13021
  • Jan 27 23:05
    straight-shoota labeled #13021
  • Jan 27 23:05
    straight-shoota labeled #13021
  • Jan 27 23:05
    straight-shoota labeled #13021
George Dietrich
@Blacksmoke16
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.

2 replies
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
Sean Gregory
@skinnyjames

@Blacksmoke16 athena console ended up being pretty slick. Thanks.

Now I just need to dig myself out of the hole I made by using with ... yield. :) Hoping this one moves forward.

George Dietrich
@Blacksmoke16
:muscle: glad to hear! any issues/questions feel free to ping me
id also suggest using the latest commit, save yourself from some breaking changes next release, and give you access to the table gen