w-stdlib 0.0.6 → 0.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/w-stdlib/core_ext/array.rb +21 -0
- data/w-stdlib.gemspec +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c7f832abbc8f5051f91bb28b7387190d1f798fa04f06a0ac7b113501102a86f9
|
4
|
+
data.tar.gz: 675259a0db48cf498afd41086e53009f82df0d9158b47ac25d1f5ecfe92ae817
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 164c5094b4b58236da56fcb5f6011a1c46b576792026140d126f0c6ab7d95b01613bf3a6b5684849be7773e9c7bec3a82b0d52c7222356bbcebd716feee7c03e
|
7
|
+
data.tar.gz: a48e11c480814ec22792362da37c81df326bd2fe39473d27c6e84553a74f9ba0bb2b1a5e387938ba35c8367a835daeee1bc8e72408fa7d6a2e21ef7ad56fa46b
|
@@ -5,6 +5,8 @@ require_relative './string'
|
|
5
5
|
using StringExt
|
6
6
|
|
7
7
|
module ArrayExt
|
8
|
+
SearchResult = Struct.new(:index, :value)
|
9
|
+
|
8
10
|
refine Array do
|
9
11
|
def tail
|
10
12
|
self[1..self.length]
|
@@ -43,6 +45,25 @@ module ArrayExt
|
|
43
45
|
each { puts _1.to_s }
|
44
46
|
end
|
45
47
|
|
48
|
+
def search_from(i, direction=1, &blk)
|
49
|
+
loop do
|
50
|
+
i += direction
|
51
|
+
return nil if i < 0 || i > length-1
|
52
|
+
|
53
|
+
item = self[i]
|
54
|
+
return SearchResult.new(i, item) if yield(item)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def search_forward(i, &blk)
|
59
|
+
search_from(i, 1, &blk)
|
60
|
+
end
|
61
|
+
|
62
|
+
def search_backward(i, &blk)
|
63
|
+
search_from(i, -1, &blk)
|
64
|
+
end
|
65
|
+
|
66
|
+
|
46
67
|
def search(str)
|
47
68
|
select do
|
48
69
|
s = block_given? ? yield(_1) : _1.to_s
|
data/w-stdlib.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |g|
|
2
2
|
g.name = 'w-stdlib'
|
3
|
-
g.version = '0.0.
|
3
|
+
g.version = '0.0.7'
|
4
4
|
g.summary = 'Pre-alpha package that contains abstractions that I find useful when scripting. Not suitable for production use. Breaking changes highly likely even with minor version bumps. Use at your own risk'
|
5
5
|
g.description = g.summary
|
6
6
|
g.authors = ['will@btlr.dev']
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: w-stdlib
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- will@btlr.dev
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-02-
|
11
|
+
date: 2022-02-20 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Pre-alpha package that contains abstractions that I find useful when
|
14
14
|
scripting. Not suitable for production use. Breaking changes highly likely even
|