Quick actions

cmd+k|ctrl+k

Navigation

Languages

<aaa bbb ccc> ==> 'aaa, bbb and ccc'

Snippet info

Language

Raku

Visibility

public

Author

raiph.mellor

Created

2021-09-15T20:31:33.418648Z

Updated

2021-09-15T21:29:56.535177Z

# See https://stackoverflow.com/questions/67305345/
# how-to-concatenate-list-objects-into-a-string-and-separate-the-last-2-objects-wi

# `given` establishes the "topic" aka "it"
# `<foo bar>` is a list of two strings, 'foo' and 'bar'
# `put` prints a string and appends a newline 
# `.[...]` is an index/slice of "it" treated as a list/array. 
# With no LHS `^` means "zero up to...". (Mnemonic `^` points "up to".)
# `*` inside a list/array index is the list/array's length.
# `~` is infix string concat op. (Mnemonic: looks like a piece of string.)

given <aaa bbb ccc> { put .[^(*-1)] .join(', ') ~ ' and ' ~ .[*-1] }
INFO