https://github.com/jmettraux/tresse
a stupid each+map+reduce thing
https://github.com/jmettraux/tresse
ruby thread
Last synced: 12 months ago
JSON representation
a stupid each+map+reduce thing
- Host: GitHub
- URL: https://github.com/jmettraux/tresse
- Owner: jmettraux
- License: mit
- Created: 2019-09-14T23:15:41.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2020-09-25T14:48:22.000Z (almost 6 years ago)
- Last Synced: 2025-06-22T20:18:50.644Z (about 1 year ago)
- Topics: ruby, thread
- Language: Ruby
- Size: 33.2 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# tresse
A poorly thought out and stupid source+map+reduce contraption.
You source one or more pieces of data, map them a couple of times then reduce them.
By default, the whole of Tresse uses 8 work threads, it can be changed:
```ruby
Tresse.max_work_thread_count # => 8
Tresse.max_work_thread_count = 10
Tresse.max_work_thread_count # => 10
```
## use
Two sources flattened together
```ruby
r =
Tresse::Group.new('test0')
.source { (0..3).to_a }
.source { (4..9).to_a }
.values # or .flatten
.sort
r #=> (0..9).to_a
```
Combining two sources again
```ruby
r =
Tresse::Group.new('test0')
.source { (0..3).to_a }
.source { ('a'..'c').to_a }
.map { |e| e.collect { |e| e * 2 } }
.values # or .flatten
r
# => [ 0, 2, 4, 6, 'aa', 'bb', 'cc' ]
# or
# => [ 'aa', 'bb', 'cc', 0, 2, 4, 6 ]
```
Each can be used, the outcome of its block is discarded
```ruby
t = []
# collecting on the side
r =
Tresse::Group.new('test0')
.source { (0..3).to_a }
.source { ('a'..'c').to_a }
.each { |e| t << e.collect { |e| e * 2 } }
.values
r
# => [ 0, 1, 2, 3, 'a', 'b', 'c' ]
# or
# => [ 'a', 'b', 'c', 0, 1, 2, 3 ]
t
# => [ [ 0, 2, 4, 6 ], [ 'aa', 'bb', 'cc' ] ]
# or
# => [ [ 'aa', 'bb', 'cc' ], [ 0, 2, 4, 6 ] ]
```
## license
MIT, see [LICENSE.txt](LICENSE.txt)