This channel is intended for people just starting with the Raku Programming Language (raku.org). Logs are available at irclogs.raku.org/raku-beginner/live.html Set by lizmat on 8 June 2022. |
|||
00:25
fennewald joined
|
|||
fennewald | hey, what's the way to do Optional return types. Specifically, if I define a function that will either return a `Str` or nothing at all, what is the best way to do that? | 00:27 | |
01:08
Kaiepi left
|
|||
jaguart | Just set the return type to Str - the 'or Nil' is implicit | 02:58 | |
docs.raku.org/language/functions#R...onstraints | 03:00 | ||
Says: `Note that Nil and Failure are exempt from return type constraints and can be returned from any routine, regardless of its constraint` | |||
I'm not that experienced, but I wonder if the Signature constraint e.g. sub foo(--> Int) {} somewhat differs from the trait-like syntax: sub foo() returns Int {}; | 03:04 | ||
in that under introspection, the Signature of the first sub is different from the signature of the second. | |||
and maybe that makes a difference for multis? | 03:05 | ||
oh - just found this too: docs.raku.org/type/Signature#returns which says 'the pointy arrow form is always preferred' | 03:15 | ||
03:26
razetime joined
04:31
Heptite left
08:41
Kaiepi joined
|
|||
Nemokosch | fennewald: more to this. the `Str` type signature covers "definite" and "indefinite" values of `Str` | 10:17 | |
"definite" values are concrete instances with appropriate data while the only indefinite instance is the type object `Str` itself. You can denote that you want definite content with `Str:D` and you can mark your data as "indefinite" using `Str:U` | 10:18 | ||
in some sense, `Str` can stand for "nothing at all, *as a string*". Same for all type objects. This means that you can retain strict types with missing values as well, if that's what you want | 10:21 | ||
by the way: since anything ultimately descends from `Mu`, you can catch all type objects by `Mu:U` | 10:24 | ||
10:44
razetime left
14:56
Heptite joined
15:41
jgaz joined
15:48
jgaz left
15:50
jgaz joined
15:53
razetime joined
16:56
jgaz left
17:22
razetime left
17:23
jgaz joined
21:02
Kaipei joined
21:04
Kaiepi left
21:19
QhpAptyj9hj0RQwM joined
22:01
jgaz left
23:11
Kaipei left
23:53
Kaipei joined
|