| 29 Nov 2025 | |||
| camelia | True | 16:09 | |
| Voldenet | kinda bruteforce-ish but it's what you have to do anyway | ||
| lizmat | that depends on the stringification of (1,2)... which may be troublesome for something like: | 16:10 | |
| ashfield | yeah, it's not impossible to write a function/method to iterate over the second list and test with eqv | ||
| lizmat | m: say <<a "b c" d>> | ||
| camelia | (a b c d) | ||
| ashfield | I'll have a look at ValueList as well | ||
| lizmat | m: say ((1, 2), (3, 4)).first({ $_ eqv (1, 2) }).so | 16:11 | |
| camelia | True | ||
| lizmat | eqv could work | ||
| m: say ([1, 2], (3, 4)).first({ $_ eqv (1, 2) }).so | |||
| camelia | False | ||
| ashfield | I was just wondering if there was some library function I was overlooking or something for "contains-list" or something | ||
| Voldenet | ah, right, eqv could work better | ||
| lizmat | well, as Voldenet pointed out, there's .first | ||
| Voldenet | or smartmatch | ||
| sadly most languages don't contain such thing for lists comparison | 16:13 | ||
| the whole .so approach has caveat | 16:17 | ||
| m: say ([1, 2], (3, 4)).first({ $_ ~~ (1, 2) }).so # this works | |||
| camelia | True | ||
| Voldenet | m: say ([1, 2], ()).first({ $_ ~~ () }).so # this doesn't, because .so on empty list is False | 16:18 | |
| camelia | False | ||
| Voldenet | m: say ([1, 2], (3, 4)).first({ $_ ~~ (1, 2) }).defined # this works as long as you don't try to look for Nil | 16:19 | |
| camelia | True | ||
| Voldenet | so… | 16:20 | |
| m: say ([1, 2], (3, 4)).first({ $_ ~~ (1, 2) }, :k).defined # this is probably the best way, it returns index of the found value or nil | |||
| camelia | True | ||
| ashfield | ah, right, I misread what .first was doing earlier | 16:22 | |
| m: say [||] ((1,2),(3,4)).map: { $_ eqv (1,2) } | 16:23 | ||
| camelia | True | ||
| Voldenet | || will not work as you think | 16:24 | |
| ashfield | oh really? | ||
| Voldenet | m: say [||] ((1,2),(3,4),(5,6)).map: { say $_; $_ eqv (1,2) } # no short-circuiting | ||
| camelia | (1 2) (3 4) (5 6) True |
||
| Voldenet | btw, I suggest a very tiny addition to standard library | 16:25 | |
| ashfield | oh, yeah, I understand that it's making the whole list of bools first, if that's what you mean | ||
| I suppose that's less efficient than .first | |||
| Voldenet | m: say ([1, 2], (3,4), Nil).contains((1, 2)) # this could simply do smartmatching | ||
| camelia | Calling '.contains' on a List, did you mean '$item (elem) @list'? True in block <unit> at <tmp> line 1 Use of Nil in string context in block <unit> at <tmp> line 1 |
||
| ugexe | contains on a list stringifies the lhs | 16:26 | |
| m: say ([1,2],[3,4]).contains((2,3)) | 16:28 | ||
| camelia | Calling '.contains' on a List, did you mean '$item (elem) @list'? True in block <unit> at <tmp> line 1 |
||
| Voldenet | indeed, but it'd be very convenient to have special .contains for Iterable | 16:29 | |
| m: sub has(Iterable $x, $y) { my $n = $x.iterator; until (my $item := $n.pull-one) =:= IterationEnd { return True if $item ~~ $y; }; False }; say ([1, 2], (3,4), Nil, 1).&has((1,2)); | 16:36 | ||
| camelia | True | ||
| Voldenet | additional bonus is that it runs ACCEPTS so this is possible | 16:37 | |
| m: sub has(Iterable $x, $y) { my $n = $x.iterator; until (my $item := $n.pull-one) =:= IterationEnd { return True if $item ~~ $y; }; False }; say ([1, 2], (3,4), Nil, 1).&has(Int); | |||
| camelia | True | ||
| Voldenet | and additional downside is that it runs ACCEPTS of course, strict equality is useful in some cases | 16:40 | |
| disbot6 | <aruniecrisps> @SmokeMachine @holmdunc @librasteve I can start working on the red migrations module, but I don't think I'll have anything major done in time for raku advent let's see | 21:54 | |
| <aruniecrisps> Or actually maybe I will, I probably just have tonm sit down and grind it out | |||
| <librasteve> arun: thanks for hacking on this ... just shout out if you need any help | 22:15 | ||
| <librasteve> Voldenet: I like this idea of special contains for Iterables ... perhaps a raku problem solving issue? | 22:16 | ||