[#98645] [Ruby master Misc#16933] DevelopersMeeting20200618Japan — mame@...

Issue #16933 has been reported by mame (Yusuke Endoh).

14 messages 2020/06/04

[#98663] [Ruby master Bug#16936] `make check TESTS="-n !/Foo#method/"` not skipping the test case — jaruga@...

Issue #16936 has been reported by jaruga (Jun Aruga).

13 messages 2020/06/05

[#98772] [Ruby master Bug#16959] Weakmap has specs and third-party usage despite being a private API — headius@...

Issue #16959 has been reported by headius (Charles Nutter).

13 messages 2020/06/12

[#98826] [Ruby master Feature#16963] Remove English.rb from Ruby 2.8/3.0 — hsbt@...

Issue #16963 has been reported by hsbt (Hiroshi SHIBATA).

9 messages 2020/06/16

[#98920] [Ruby master Bug#16978] Ruby should not use realpath for __FILE__ — v.ondruch@...

Issue #16978 has been reported by vo.x (Vit Ondruch).

24 messages 2020/06/23

[#98947] [Ruby master Feature#16986] Anonymous Struct literal — ko1@...

Issue #16986 has been reported by ko1 (Koichi Sasada).

66 messages 2020/06/26

[#98964] [Ruby master Feature#16989] Sets: need ♥️ — marcandre-ruby-core@...

Issue #16989 has been reported by marcandre (Marc-Andre Lafortune).

33 messages 2020/06/26

[#98965] [Ruby master Feature#16990] Sets: operators compatibility with Array — marcandre-ruby-core@...

Issue #16990 has been reported by marcandre (Marc-Andre Lafortune).

11 messages 2020/06/26

[#98968] [Ruby master Feature#16993] Sets: from hash keys using Hash#key_set — marcandre-ruby-core@...

Issue #16993 has been reported by marcandre (Marc-Andre Lafortune).

10 messages 2020/06/26

[#98997] [Ruby master Feature#17000] 2.7.2 turns off deprecation warnings by deafult — mame@...

Issue #17000 has been reported by mame (Yusuke Endoh).

16 messages 2020/06/30

[ruby-core:98712] [Ruby master Feature#16946] Add an `intersperse` method

From: shevegen@...
Date: 2020-06-10 13:12:23 UTC
List: ruby-core #98712
Issue #16946 has been updated by shevegen (Robert A. Heiler).


Interesting idea.

In particular that use case:

  'Hello'.intersperse('-') # => "H-e-l-l-o"

I actually had that use case every now and then, in a related manner.

For example in bioinformatics, you may have a long nucleotide sequence of A T C G
stored in flat files (usually).

Then, you may wish to show a given sequence like:

    ATCAGGCAT

I tend to modify it via:

    ATC|AGG|CAT

for display purposes sometimes. This makes it easier to 
show where a new codon (triplet) begins. (I also show
numbers on top, to make this even easier to count visually.)

So the '|' in the above example I tend to use sometimes because
it simply makes it easier to read the result.

(I am aware that your suggestion is to split on every char by
default, so it would be A|T|C etc... instead, but we could keep
this method flexible, and allow both at how many chars it may
add the intersperse-character, in addition to specifying which
character it is, such as '-','|' or '|'.)

For example:

    "ATGCCG".intersperse('|', 3) # Or something like that; I may have
                                 # miscounted but the 3 would mean to
                                 # split at every 3 chars; default is
                                 # 1 for every char. And if I miscounted
                                 # then it would be 2, and 0. Off by one
                                 # errors ... :P

> I'm aware that I can achieve the above with built-in methods, but it's quite
> cumbersome: (requiring regular expressions / intermediate arrays)

Not sure if it is cumbersome; I do it currently as-is. But even if it is not
cumbersome, I think your proposal still has merit.

So personally I am slightly in favour of it. I should add that I don't that often
have a need for the described use case, but sometimes I have. Then I tend to
google for stack overflow answers and copy/paste them ... I am only half-kidding
actually. :P

May be useful if other folks can say whether they have had a use case; this may
help the ruby team to assess how beneficial such a method would be, objectively.

(I have no particular opinion on the method on Arrays though. Not sure if I had a
use case for Arrays, but for Strings, most definitely. I am also curious what
sawa thinks of the idea if he is still active on the issue tracker.)

----------------------------------------
Feature #16946: Add an `intersperse` method
https://bugs.ruby-lang.org/issues/16946#change-86063

* 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>

In This Thread