scan_left 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c1557332192560cf4af4dadfe859d6af3daa27fb7a15c4e73095cfbb3edc8e08
4
- data.tar.gz: e868d3a5e20160daf7aae34d13a53cb28c8e92a63eda2efe0327bcd14e554421
3
+ metadata.gz: 6f17ebc3bc1c0efac49788a32791e641484601143338d20256955610d9cf32ad
4
+ data.tar.gz: 6d4c65c014fde57ecbf17a76946be7aba809bc1c35e404064549d56eff84c651
5
5
  SHA512:
6
- metadata.gz: 3dd492ba1423dcf94da46b80886e82eee00bf4316a788a8bb56a9650d89d2347a3bc84ebe0b89bd7ba2a4661396879f1804d8453c9ac20646756b3a9589dcc6c
7
- data.tar.gz: 7fe9dd080e5a6eb203966779f7fab8bc8e52b796bebcadeb9e677564804ee654fe013e25f4c4f919489718e24a9291198aa8328be1157dcd7d68a51f2e9ede71
6
+ metadata.gz: 8745ddd8bf3bab39029173a7a415a6f1a61de6d704e0b86b11a3f86d92f539f984d727a8c6cd00dd1f233c505b35b0bf39ad24ada01787649e4df83c88ece6aa
7
+ data.tar.gz: f923f89e2ee99a13e32597dc5535eaff2cfd520815e6287889e558079545b9d950fb7fc913010c2f8952bc61bac208c1f40a0bcbd86aecd56ac5b5c3fdb37b84
data/CHANGELOG.md CHANGED
@@ -5,11 +5,15 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
5
5
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
6
 
7
7
  ## [Unreleased]
8
+
9
+ ## [0.2.0] - 2020-05-14
8
10
  ### Added
11
+ - Optional refinement to add a `#scan_left` directly to `Enumerable`
12
+ - Badges in README.md for tests, gem version, and docs
13
+ - Documentation link in gemspec to rubydoc.info
9
14
 
10
15
  ### Changed
11
-
12
- ### Removed
16
+ - Improved YARD doc formatting for RubyDoc.info
13
17
 
14
18
  ## [0.1.0] - 2020-05-08
15
19
  ### Added
@@ -29,6 +33,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
29
33
  - Initial gem project structure
30
34
  - Initial CHANGELOG.md based on keepachangelog.com
31
35
 
32
- [Unreleased]: https://github.com/panorama-ed/scan_left/compare/v0.1.0...HEAD
36
+ [Unreleased]: https://github.com/panorama-ed/scan_left/compare/v0.2.0...HEAD
37
+ [0.2.0]: https://github.com/panorama-ed/scan_left/compare/v0.1.0...v0.2.0
33
38
  [0.1.0]: https://github.com/panorama-ed/scan_left/compare/v0.0.1...v0.1.0
34
39
  [0.0.1]: https://github.com/panorama-ed/scan_left/releases/tag/v0.0.1
data/Gemfile.lock CHANGED
@@ -12,7 +12,7 @@ GIT
12
12
  PATH
13
13
  remote: .
14
14
  specs:
15
- scan_left (0.1.0)
15
+ scan_left (0.2.0)
16
16
 
17
17
  GEM
18
18
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -1,6 +1,12 @@
1
+ # scan_left
1
2
  ![Tests](https://github.com/panorama-ed/scan_left/workflows/Tests/badge.svg)
2
3
 
3
- # scan_left
4
+ [![Yard Docs](http://img.shields.io/badge/yard-docs-blue.svg)](http://rubydoc.info/github/panorma-ed/scan_left)
5
+ [![Docs Coverage](http://inch-ci.org/github/panorama-ed/scan_left.png)](http://inch-ci.org/github/panorama-ed/scan_left)
6
+
7
+ [![Gem Version](https://img.shields.io/gem/v/scan_left.svg)](https://rubygems.org/gems/scan_left)
8
+ [![Gem Downloads](https://img.shields.io/gem/dt/scan_left.svg)](https://rubygems.org/gems/scan_left)
9
+
4
10
  A tiny Ruby gem to provide the `#scan_left` operation on any Ruby
5
11
  `Enumerable`.
6
12
 
@@ -32,12 +38,12 @@ series.
32
38
 
33
39
  The key differences between `#inject` and `#scan_left` are:
34
40
 
35
- 1. Incremental results: `#scan_left` returns a series of results
41
+ 1. **Incremental results**: `#scan_left` returns a series of results
36
42
  after processing each element of the input series. `#inject`
37
43
  returns a single value, which equals the final result in the
38
44
  series returned by `#scan_left`.
39
45
 
40
- 2. Laziness: `#scan_left` can preserve the laziness of the input
46
+ 2. **Laziness**: `#scan_left` can preserve the laziness of the input
41
47
  series. As each incremental result is read from the output
42
48
  series, the actual calculation is lazily performed against the
43
49
  input. `#inject` cannot be a a lazy operation in general, as its
@@ -46,8 +52,10 @@ The key differences between `#inject` and `#scan_left` are:
46
52
 
47
53
  ## Examples
48
54
 
49
- ```
50
- require 'scan_left'
55
+ ```ruby
56
+ require "scan_left"
57
+
58
+ # For comparison, results from #inject are shown as well:
51
59
 
52
60
  ScanLeft.new([]).scan_left(0) { |s, x| s + x } == [0]
53
61
  [].inject(0) { |s, x| s + x } == 0
@@ -57,6 +65,18 @@ ScanLeft.new([1]).scan_left(0) { |s, x| s + x } == [0, 1]
57
65
 
58
66
  ScanLeft.new([1, 2, 3]).scan_left(0) { |s, x| s + x } == [0, 1, 3, 6]
59
67
  [1, 2, 3].inject(0) { |s, x| s + x } == 6
68
+
69
+ # OPTIONAL: To avoid explicitly using the `ScanLeft` class, you may
70
+ # choose to use the provided refinement on Enumerable.
71
+ #
72
+ # This refinement adds a `#scan_left` method directly to Enumerable
73
+ # for a more concise syntax.
74
+
75
+ using EnumerableWithScanleft
76
+
77
+ [].scan_left(0) { |s, x| s + x } => [0]
78
+ [1].scan_left(0) { |s, x| s + x } => [0, 1]
79
+ [1, 2, 3].scan_left(0) { |s, x| s + x } => [0, 1, 3, 6]
60
80
  ```
61
81
 
62
82
  ## Further Reading
data/lib/scan_left.rb CHANGED
@@ -1,14 +1,16 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "scan_left/version"
4
-
5
3
  # Original author: [Marc Siegel](https://github.com/ms-ati).
6
4
 
7
- # Provides the `#scan_left` operation on any Enumerable.
5
+ require "scan_left/enumerable_with_scan_left"
6
+ require "scan_left/version"
7
+
8
+ # Provides the {#scan_left} operation on any Enumerable.
8
9
  class ScanLeft
10
+ # @return [Enumerable] Stream to transform via {#scan_left}
9
11
  attr_reader :enumerable
10
12
 
11
- # @param [Enumerable] enumerable Stream to transform via `scan_left`
13
+ # @param [Enumerable] enumerable Stream to transform via {#scan_left}
12
14
  def initialize(enumerable)
13
15
  @enumerable = enumerable
14
16
  end
@@ -20,16 +22,16 @@ class ScanLeft
20
22
  #
21
23
  # @return [Enumerable] Generate a stream of intermediate states
22
24
  # resulting from applying a binary operator. Equivalent to a
23
- # stream of `#inject` calls on first N elements, increasing N from
25
+ # stream of +#inject+ calls on first N elements, increasing N from
24
26
  # zero to the size of the stream. NOTE: Preserves laziness if
25
- # `enumerable` is lazy.
27
+ # +enumerable+ is lazy.
26
28
  #
27
29
  # @param initial [Object] Initial state value to yield.
28
30
  #
29
31
  # @yield [memo, obj] Invokes given block with previous state value
30
- # `memo` and next element of the stream `obj`.
32
+ # +memo+ and next element of the stream +obj+.
31
33
  #
32
- # @yieldreturn [Object] The next state value for `memo`.
34
+ # @yieldreturn [Object] The next state value for +memo+.
33
35
  def scan_left(initial)
34
36
  memo = initial
35
37
  outs = enumerable.map { |*obj| memo = yield(memo, *obj) }
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ # This refines `Enumerable` to add a `#scan_left` method. This allows
4
+ # for a more natural syntax than explicitly using the `ScanLeft`
5
+ # class.
6
+ #
7
+ # Without using this refinement:
8
+ # ScanLeft.new([1,2,3]).scan_left(0, &:+) => [0, 1, 3, 6]
9
+ #
10
+ # Using this refinement:
11
+ # [1,2,3].scan_left(0, &:+) => [0, 1, 3, 6]
12
+ #
13
+ #
14
+ # Example:
15
+ #
16
+ # class Foo
17
+ # using EnumerableWithScanLeft
18
+ #
19
+ # def bar(x)
20
+ # [1,2,3].scan_left(x, &:+)
21
+ # end
22
+ # end
23
+ #
24
+ # Foo.new.bar(10) => [10, 11, 13, 16]
25
+ module EnumerableWithScanLeft
26
+ refine Enumerable do
27
+ def scan_left(initial, &block)
28
+ ScanLeft.new(self).scan_left(initial, &block)
29
+ end
30
+ end
31
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class ScanLeft
4
- VERSION = "0.1.0"
4
+ VERSION = "0.2.0"
5
5
  end
data/scan_left.gemspec CHANGED
@@ -22,6 +22,7 @@ Gem::Specification.new do |spec|
22
22
  spec.metadata["source_code_uri"] = spec.homepage
23
23
  spec.metadata["changelog_uri"] =
24
24
  "https://github.com/panorama-ed/scan_left/blob/master/CHANGELOG.md"
25
+ spec.metadata["documentation_uri"] = "https://rubydoc.info/gems/scan_left"
25
26
  else
26
27
  raise "RubyGems 2.0 or newer is required to protect against "\
27
28
  "public gem pushes."
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: scan_left
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marc Siegel
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-05-08 00:00:00.000000000 Z
11
+ date: 2020-05-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -75,6 +75,7 @@ files:
75
75
  - bin/console
76
76
  - bin/setup
77
77
  - lib/scan_left.rb
78
+ - lib/scan_left/enumerable_with_scan_left.rb
78
79
  - lib/scan_left/version.rb
79
80
  - scan_left.gemspec
80
81
  homepage: https://github.com/panorama-ed/scan_left
@@ -85,6 +86,7 @@ metadata:
85
86
  homepage_uri: https://github.com/panorama-ed/scan_left
86
87
  source_code_uri: https://github.com/panorama-ed/scan_left
87
88
  changelog_uri: https://github.com/panorama-ed/scan_left/blob/master/CHANGELOG.md
89
+ documentation_uri: https://rubydoc.info/gems/scan_left
88
90
  post_install_message:
89
91
  rdoc_options: []
90
92
  require_paths:
@@ -100,8 +102,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
100
102
  - !ruby/object:Gem::Version
101
103
  version: '0'
102
104
  requirements: []
103
- rubyforge_project:
104
- rubygems_version: 2.7.6.2
105
+ rubygems_version: 3.0.8
105
106
  signing_key:
106
107
  specification_version: 4
107
108
  summary: A tiny Ruby gem to provide the 'scan_left' operation on any Ruby Enumerable.