piperator 1.1.0 → 1.3.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: 13c2413016f50d1f376666a3997bb0419fd3bbe0311913c9b2d694ab80b47083
4
- data.tar.gz: 5b452fb6d8bc029accb4c32cd5b692d377ead539cc164dd65f6aba4715d51c75
3
+ metadata.gz: 9269910cd3b64e1184e36d5569a356820a72faac26c3a06dc8fc2e5e5542c6ae
4
+ data.tar.gz: 5a38bc706afb02a408ff6e45a5dd991a05185b8e2c93025cab42f720bda636cb
5
5
  SHA512:
6
- metadata.gz: '07794c6e1760367b51fab0667afac9275fa61c81d34e1de3b1d68be245246a04d0040869e6e27f49e7d2de90057e0edddd3ab9bcba0cb0620fd4d61ac3112d7e'
7
- data.tar.gz: 372fc0fb1fc79832d312bf661019ff6f4203c702a139a3c3fe03ab8f8b2636826ade5a20fa60e288580177ae58f812320e6419ab341d9ac2bb80c51e9fa599d9
6
+ metadata.gz: 06e1e83db7fd2e8bdb6fa699168f034a97ae83fecb07f694b027f9c87c504bf934e83d08384f9201b0d5111be6d2a4bb1ca4a9567fc49e2359d5b1bc5cb4db01
7
+ data.tar.gz: 7896a21f84da09fc97b66ccb35f384fe872e1ffcca98033c388154a809560c34ac83f9ae97d8accb67fa1ebcb9d119c8c8d8550b00be2d77caf1809fb8cac6db
data/.codecov.yaml ADDED
@@ -0,0 +1,7 @@
1
+ comment: false
2
+
3
+ coverage:
4
+ status:
5
+ project:
6
+ default:
7
+ only_pulls: true
@@ -0,0 +1,41 @@
1
+ name: CI
2
+
3
+ on: [push, pull_request]
4
+
5
+ jobs:
6
+ test:
7
+ name: >-
8
+ Test (${{ matrix.os }} ${{ matrix.ruby }})
9
+ runs-on: ${{ matrix.os }}-latest
10
+ strategy:
11
+ fail-fast: false
12
+ matrix:
13
+ os: [ubuntu, macos, windows]
14
+ ruby:
15
+ - 2.3
16
+ - 2.4
17
+ - 2.5
18
+ - 2.6
19
+ - 2.7
20
+ - "3.0"
21
+ - "3.1"
22
+ - "3.2"
23
+ - jruby
24
+ - truffleruby
25
+ exclude:
26
+ - os: windows
27
+ ruby: jruby
28
+ - os: windows
29
+ ruby: truffleruby
30
+ steps:
31
+ - uses: actions/checkout@v2
32
+ - uses: ruby/setup-ruby@v1
33
+ with:
34
+ ruby-version: ${{ matrix.ruby }}
35
+ bundler-cache: true
36
+ - run: bundle exec rake
37
+ - uses: codecov/codecov-action@v2
38
+ if: ${{ matrix.os == 'ubuntu' && matrix.ruby == '3.0' }}
39
+ with:
40
+ file: ./coverage/coverage.xml
41
+ fail_ci_if_error: true
data/Gemfile CHANGED
@@ -2,3 +2,8 @@ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in piperator.gemspec
4
4
  gemspec
5
+
6
+ if RUBY_VERSION >= '2.5'
7
+ gem 'simplecov', '~> 0.21.2', group: [:development]
8
+ gem 'simplecov-cobertura', '~> 2.1.0', group: [:development]
9
+ end
data/README.md CHANGED
@@ -2,9 +2,7 @@
2
2
 
3
3
  Pipelines for streaming large collections. The pipeline enables composition of streaming pipelines with lazy enumerables.
4
4
 
5
- The library is heavily inspired by [Elixir pipe operator](https://elixirschool.com/lessons/basics/pipe-operator/) and [Node.js Stream](https://nodejs.org/api/stream.html).
6
-
7
- [![Build Status](https://travis-ci.org/lautis/piperator.svg?branch=master)](https://travis-ci.org/lautis/piperator)
5
+ The library is heavily inspired by [Elixir pipe operator](https://elixirschool.com/en/lessons/basics/pipe-operator/) and [Node.js Stream](https://nodejs.org/api/stream.html).
8
6
 
9
7
  <!-- START doctoc generated TOC please keep comment here to allow auto update -->
10
8
  <!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
@@ -69,6 +67,18 @@ Piperator.
69
67
  # => 18
70
68
  ```
71
69
 
70
+ Have reasons to defer constructing a pipe? Evaluate it lazily:
71
+
72
+ ```ruby
73
+ summing = ->(values) { values.sum }
74
+ Piperator.build
75
+ pipe(->(values) { values.lazy.map { |i| i * 3 } })
76
+ lazy do
77
+ summing
78
+ end
79
+ end.call([1, 2, 3])
80
+ ```
81
+
72
82
  There is, of course, a much more idiomatic alternative in Ruby:
73
83
 
74
84
  ```ruby
@@ -16,11 +16,12 @@ module Piperator
16
16
  #
17
17
  # @see Pipeline.$1
18
18
  def self.dsl_method(method_name)
19
- define_method(method_name) do |*arguments|
20
- @pipeline = @pipeline.send(method_name, *arguments)
19
+ define_method(method_name) do |*arguments, &block|
20
+ @pipeline = @pipeline.send(method_name, *arguments, &block)
21
21
  end
22
22
  end
23
23
 
24
+ dsl_method :lazy
24
25
  dsl_method :pipe
25
26
  dsl_method :wrap
26
27
 
data/lib/piperator/io.rb CHANGED
@@ -62,14 +62,15 @@ module Piperator
62
62
  # Reads length bytes from the I/O stream.
63
63
  #
64
64
  # @param length [Integer] number of bytes to read
65
+ # @param buffer [String] optional read buffer
65
66
  # @return String
66
- def read(length = nil)
67
+ def read(length = nil, buffer = nil)
67
68
  return @enumerator.next.tap { |e| @pos += e.bytesize } if length.nil? && readable_bytes.zero?
68
69
  @buffer.write(@enumerator.next) while !@eof && readable_bytes < (length || 1)
69
- read_with { @buffer.read(length) }
70
+ read_with { @buffer.read(length, buffer) }
70
71
  rescue StopIteration
71
72
  @eof = true
72
- read_with { @buffer.read(length) } if readable_bytes > 0
73
+ read_with { @buffer.read(length, buffer) } if readable_bytes > 0
73
74
  end
74
75
 
75
76
  # Current buffer size - including non-freed read content
@@ -6,6 +6,16 @@ module Piperator
6
6
  # For streaming purposes, it usually is desirable to have pipes that takes
7
7
  # a lazy Enumerator as an argument a return a (modified) lazy Enumerator.
8
8
  class Pipeline
9
+ # Build a new pipeline from a lazily evaluated callable or an enumerable
10
+ # object.
11
+ #
12
+ # @param block A block returning a callable(enumerable)
13
+ # @return [Pipeline] A pipeline containing only the lazily evaluated
14
+ # callable.
15
+ def self.lazy(&block)
16
+ Pipeline.new([]).lazy(&block)
17
+ end
18
+
9
19
  # Build a new pipeline from a callable or an enumerable object
10
20
  #
11
21
  # @param callable An object responding to call(enumerable)
@@ -59,6 +69,19 @@ module Piperator
59
69
  call(enumerable).to_a
60
70
  end
61
71
 
72
+ # Add a new lazily evaluated part to the pipeline.
73
+ #
74
+ # @param block A block returning a callable(enumerable) to append in
75
+ # pipeline.
76
+ # @return [Pipeline] A new pipeline instance
77
+ def lazy(&block)
78
+ callable = nil
79
+ Pipeline.new(@pipes + [lambda do |e|
80
+ callable ||= block.call
81
+ callable.call(e)
82
+ end])
83
+ end
84
+
62
85
  # Add a new part to the pipeline
63
86
  #
64
87
  # @param other A pipe to append in pipeline. Responds to #call.
@@ -1,4 +1,4 @@
1
1
  module Piperator
2
2
  # Piperator version
3
- VERSION = '1.1.0'.freeze
3
+ VERSION = '1.3.0'.freeze
4
4
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: piperator
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ville Lautanala
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-12-06 00:00:00.000000000 Z
11
+ date: 2023-08-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -60,9 +60,10 @@ executables: []
60
60
  extensions: []
61
61
  extra_rdoc_files: []
62
62
  files:
63
+ - ".codecov.yaml"
64
+ - ".github/workflows/ci.yml"
63
65
  - ".gitignore"
64
66
  - ".rspec"
65
- - ".travis.yml"
66
67
  - CHANGELOG.md
67
68
  - Gemfile
68
69
  - LICENSE.txt
@@ -80,7 +81,7 @@ homepage: https://github.com/lautis/piperator
80
81
  licenses:
81
82
  - MIT
82
83
  metadata: {}
83
- post_install_message:
84
+ post_install_message:
84
85
  rdoc_options: []
85
86
  require_paths:
86
87
  - lib
@@ -95,8 +96,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
95
96
  - !ruby/object:Gem::Version
96
97
  version: '0'
97
98
  requirements: []
98
- rubygems_version: 3.0.3
99
- signing_key:
99
+ rubygems_version: 3.2.22
100
+ signing_key:
100
101
  specification_version: 4
101
102
  summary: Composable pipelines for streaming large collections
102
103
  test_files: []
data/.travis.yml DELETED
@@ -1,10 +0,0 @@
1
- sudo: false
2
- cache: bundler
3
- language: ruby
4
- rvm:
5
- - 2.3
6
- - 2.4
7
- - 2.5
8
- - 2.6
9
- - jruby
10
- - truffleruby