[#98621] Re: Function getlogin_r()'s protoype] — Bertram Scharpf <lists@...>
FYI,
3 messages
2020/06/02
[#98947] [Ruby master Feature#16986] Anonymous Struct literal — ko1@...
Issue #16986 has been reported by ko1 (Koichi Sasada).
66 messages
2020/06/26
[#98962] [Ruby master Bug#16988] Kernel.load loads file from current directory without '.' in path — misharinn@...
Issue #16988 has been reported by TheSmartnik (Nikita Misharin).
5 messages
2020/06/26
[#98969] [Ruby master Feature#16994] Sets: shorthand for frozen sets of symbols / strings — marcandre-ruby-core@...
Issue #16994 has been reported by marcandre (Marc-Andre Lafortune).
7 messages
2020/06/26
[#100117] [Ruby master Feature#16994] Sets: shorthand for frozen sets of symbols / strings
— matz@...
2020/09/25
Issue #16994 has been updated by matz (Yukihiro Matsumoto).
[ruby-core:98726] [Ruby master Feature#16946] Add an `intersperse` method
From:
nobu@...
Date:
2020-06-11 01:47:09 UTC
List:
ruby-core #98726
Issue #16946 has been updated by nobu (Nobuyoshi Nakada).
The example for `Array` looks simple, but it would be more complicated for `String`.
Is it OK by "char", not by "grapheme cluster"?
----------------------------------------
Feature #16946: Add an `intersperse` method
https://bugs.ruby-lang.org/issues/16946#change-86082
* Author: sos4nt (Stefan Sch館ler)
* Status: Open
* Priority: Normal
----------------------------------------
Haskell has an `intersperse` function which adds a separator between elements of a list.
It would be pretty useful to have such method(s) in Ruby, too.
Examples for `Array` and `String`:
```ruby
[1, 2, 3].intersperse(0)
#=> [1, 0, 2, 0, 3]
'Hello'.intersperse('-')
#=> "H-e-l-l-o"
```
I'm aware that I can achieve the above with built-in methods, but it's quite cumbersome: (requiring regular expressions / intermediate arrays)
```ruby
[1, 2, 3].flat_map { |i| [i, 0] }[0...-1]
#=> [1, 0, 2, 0, 3]
'Hello'.gsub(/(?<=.)./, '-\0')
#=> "H-e-l-l-o"
'Hello'.chars.join('-')
#=> "H-e-l-l-o"
```
--
https://bugs.ruby-lang.org/
Unsubscribe: <mailto:ruby-core-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>