persistent-dmnd 2.0.6 β 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitlab-ci.yml +0 -202
- data/.standard.yml +1 -1
- data/README.adoc +17 -17
- data/UPSTREAM_TODO.adoc +0 -10
- data/gems.rb +1 -4
- data/lib/persistent-dmnd.rb +0 -3
- data/lib/persistent-/360/237/222/216.rb +1 -7
- data/lib/persistent_dmnd/array.rb +2 -7
- data/lib/persistent_dmnd/concurrent_ruby_support.rb +0 -5
- data/lib/persistent_dmnd/dmndifier.rb +8 -9
- data/lib/persistent_dmnd/everywhere.rb +0 -2
- data/lib/persistent_dmnd/hash.rb +2 -27
- data/lib/persistent_dmnd/is_persistent.rb +0 -3
- data/lib/persistent_dmnd/jruby_9_2_set_workaround.rb +1 -4
- data/lib/persistent_dmnd/self_conversion.rb +0 -7
- data/lib/persistent_dmnd/set.rb +2 -7
- data/lib/persistent_dmnd/version.rb +1 -4
- data/persistent-dmnd.gemspec +10 -10
- metadata +38 -12
- data/lib/persistent_dmnd/jruby_workaround.rb +0 -107
- data/lib/persistent_dmnd/ruby_1_9_and_2_0_support.rb +0 -48
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f0960914486fd0d32657f0a2ac0bc39fac7939e6334a6fccddc0276643dc9872
|
4
|
+
data.tar.gz: beffd955c885fc84848b3ae6e712290773c62d1a7f88d852c78d26ddbe8f69ad
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 897d9bfc154865911c0be282ce3bb2cc19161b265e0c7244e39c52db5c1b40a92b188122233117404e636ef562509627366aabbbf54b8a55e206dccd8979d88f
|
7
|
+
data.tar.gz: 25aa9be4e63456038a288d6d6155c63306714102516d143d6f393a442778d164e01bc2ce8c40028de96eb919cf551f847d307cf8f893c3189207d745b47d4ef2
|
data/.gitlab-ci.yml
CHANGED
@@ -1,125 +1,3 @@
|
|
1
|
-
# MRI Ruby version list:
|
2
|
-
# https://hub.docker.com/r/library/ruby/tags/
|
3
|
-
|
4
|
-
testruby_1_9_3:
|
5
|
-
image: "ruby:1.9.3"
|
6
|
-
|
7
|
-
cache: # Cache gems in between builds
|
8
|
-
paths:
|
9
|
-
- vendor/ruby
|
10
|
-
|
11
|
-
before_script:
|
12
|
-
- apt-key adv --keyserver keyserver.ubuntu.com --recv-keys AA8E81B4331F7F50 7638D0442B90D010 8B48AD6246925553
|
13
|
-
- echo "deb [trusted=yes] http://archive.debian.org/debian/ jessie main contrib non-free" | tee /etc/apt/sources.list
|
14
|
-
- apt-get update # Add UTF-8 support
|
15
|
-
- apt-get install -y locales >/dev/null # |
|
16
|
-
- echo "en_US UTF-8" > /etc/locale.gen # |
|
17
|
-
- locale-gen en_US.UTF-8 # |
|
18
|
-
- export LANG=en_US.UTF-8 # |
|
19
|
-
- export LANGUAGE=en_US:en # |
|
20
|
-
- export LC_ALL=en_US.UTF-8 # v
|
21
|
-
- ruby -v # Print out ruby version for debugging
|
22
|
-
- gem install bundler -v '< 2' # Bundler is not installed with the image
|
23
|
-
- bundle install -j $(nproc) --path vendor # Install dependencies into ./vendor/ruby
|
24
|
-
|
25
|
-
script:
|
26
|
-
- bin/rspec
|
27
|
-
|
28
|
-
testruby_2_0:
|
29
|
-
image: "ruby:2.0"
|
30
|
-
|
31
|
-
cache: # Cache gems in between builds
|
32
|
-
paths:
|
33
|
-
- vendor/ruby
|
34
|
-
|
35
|
-
before_script:
|
36
|
-
- apt-key adv --keyserver keyserver.ubuntu.com --recv-keys AA8E81B4331F7F50 7638D0442B90D010 8B48AD6246925553
|
37
|
-
- echo "deb [trusted=yes] http://archive.debian.org/debian/ jessie main contrib non-free" | tee /etc/apt/sources.list
|
38
|
-
- apt-get update # Add UTF-8 support
|
39
|
-
- apt-get install -y locales >/dev/null # |
|
40
|
-
- echo "en_US UTF-8" > /etc/locale.gen # |
|
41
|
-
- locale-gen en_US.UTF-8 # |
|
42
|
-
- export LANG=en_US.UTF-8 # |
|
43
|
-
- export LANGUAGE=en_US:en # |
|
44
|
-
- export LC_ALL=en_US.UTF-8 # v
|
45
|
-
- ruby -v # Print out ruby version for debugging
|
46
|
-
- gem install bundler:'< 2' # Bundler is not installed with the image
|
47
|
-
- bundle install -j $(nproc) --path vendor # Install dependencies into ./vendor/ruby
|
48
|
-
|
49
|
-
script:
|
50
|
-
- bin/rspec
|
51
|
-
|
52
|
-
testruby_2_1:
|
53
|
-
image: "ruby:2.1"
|
54
|
-
|
55
|
-
cache: # Cache gems in between builds
|
56
|
-
paths:
|
57
|
-
- vendor/ruby
|
58
|
-
|
59
|
-
before_script:
|
60
|
-
- apt-key adv --keyserver keyserver.ubuntu.com --recv-keys AA8E81B4331F7F50 7638D0442B90D010 8B48AD6246925553
|
61
|
-
- echo "deb [trusted=yes] http://archive.debian.org/debian/ jessie main contrib non-free" | tee /etc/apt/sources.list
|
62
|
-
- apt-get update # Add UTF-8 support
|
63
|
-
- apt-get install -y locales >/dev/null # |
|
64
|
-
- echo "en_US UTF-8" > /etc/locale.gen # |
|
65
|
-
- locale-gen en_US.UTF-8 # |
|
66
|
-
- export LANG=en_US.UTF-8 # |
|
67
|
-
- export LANGUAGE=en_US:en # |
|
68
|
-
- export LC_ALL=en_US.UTF-8 # v
|
69
|
-
- ruby -v # Print out ruby version for debugging
|
70
|
-
- gem install bundler:'< 2' # Bundler is not installed with the image
|
71
|
-
- bundle install -j $(nproc) --path vendor # Install dependencies into ./vendor/ruby
|
72
|
-
|
73
|
-
script:
|
74
|
-
- bin/rspec
|
75
|
-
|
76
|
-
testruby_2_2:
|
77
|
-
image: "ruby:2.2"
|
78
|
-
|
79
|
-
cache: # Cache gems in between builds
|
80
|
-
paths:
|
81
|
-
- vendor/ruby
|
82
|
-
|
83
|
-
before_script:
|
84
|
-
- apt-key adv --keyserver keyserver.ubuntu.com --recv-keys AA8E81B4331F7F50 7638D0442B90D010 8B48AD6246925553
|
85
|
-
- echo "deb [trusted=yes] http://archive.debian.org/debian/ jessie main contrib non-free" | tee /etc/apt/sources.list
|
86
|
-
- apt-get update # Add UTF-8 support
|
87
|
-
- apt-get install -y locales >/dev/null # |
|
88
|
-
- echo "en_US UTF-8" > /etc/locale.gen # |
|
89
|
-
- locale-gen en_US.UTF-8 # |
|
90
|
-
- export LANG=en_US.UTF-8 # |
|
91
|
-
- export LANGUAGE=en_US:en # |
|
92
|
-
- export LC_ALL=en_US.UTF-8 # v
|
93
|
-
- ruby -v # Print out ruby version for debugging
|
94
|
-
- gem install bundler:'< 2' # Bundler is not installed with the image
|
95
|
-
- bundle install -j $(nproc) --path vendor # Install dependencies into ./vendor/ruby
|
96
|
-
|
97
|
-
script:
|
98
|
-
- bin/rspec
|
99
|
-
|
100
|
-
testruby_2_3:
|
101
|
-
image: "ruby:2.3"
|
102
|
-
|
103
|
-
cache: # Cache gems in between builds
|
104
|
-
paths:
|
105
|
-
- vendor/ruby
|
106
|
-
|
107
|
-
before_script:
|
108
|
-
- echo "deb [trusted=yes] http://archive.debian.org/debian/ stretch main contrib non-free" | tee /etc/apt/sources.list
|
109
|
-
- apt-get update >/dev/null # Add UTF-8 support
|
110
|
-
- apt-get install -y locales >/dev/null # |
|
111
|
-
- echo "en_US UTF-8" > /etc/locale.gen # |
|
112
|
-
- locale-gen en_US.UTF-8 # |
|
113
|
-
- export LANG=en_US.UTF-8 # |
|
114
|
-
- export LANGUAGE=en_US:en # |
|
115
|
-
- export LC_ALL=en_US.UTF-8 # v
|
116
|
-
- ruby -v # Print out ruby version for debugging
|
117
|
-
- gem install bundler:'< 2' # Bundler is not installed with the image
|
118
|
-
- bundle install -j $(nproc) --path vendor # Install dependencies into ./vendor/ruby
|
119
|
-
|
120
|
-
script:
|
121
|
-
- bin/rspec
|
122
|
-
|
123
1
|
testruby_2_4:
|
124
2
|
image: "ruby:2.4"
|
125
3
|
|
@@ -240,86 +118,6 @@ testruby_3_3:
|
|
240
118
|
script:
|
241
119
|
- bin/rspec
|
242
120
|
|
243
|
-
testjruby_1_7:
|
244
|
-
image: "jruby:1.7"
|
245
|
-
|
246
|
-
cache: # Cache gems in between builds
|
247
|
-
paths:
|
248
|
-
- vendor/ruby
|
249
|
-
|
250
|
-
before_script:
|
251
|
-
- echo "deb [trusted=yes] http://archive.debian.org/debian/ stretch main contrib non-free" | tee /etc/apt/sources.list
|
252
|
-
- apt-get update >/dev/null # Add UTF-8 support
|
253
|
-
- apt-get install -y locales >/dev/null # |
|
254
|
-
- echo "en_US UTF-8" > /etc/locale.gen # |
|
255
|
-
- locale-gen en_US.UTF-8 # |
|
256
|
-
- export LANG=en_US.UTF-8 # |
|
257
|
-
- export LANGUAGE=en_US:en # |
|
258
|
-
- export LC_ALL=en_US.UTF-8 # v
|
259
|
-
- apt-get install -y git >/dev/null # Add git binary
|
260
|
-
- export JRUBY_OPTS=--dev # Faster test runs
|
261
|
-
- ruby -v # Print out ruby version for debugging
|
262
|
-
- gem install bundler:'< 2' # Bundler is not installed with the image
|
263
|
-
- bundle install -j $(nproc) --path vendor # Install dependencies into ./vendor/ruby
|
264
|
-
|
265
|
-
script:
|
266
|
-
- bin/rspec
|
267
|
-
|
268
|
-
testjruby_9_0:
|
269
|
-
image: "jruby:9.0"
|
270
|
-
|
271
|
-
cache: # Cache gems in between builds
|
272
|
-
paths:
|
273
|
-
- vendor/ruby
|
274
|
-
|
275
|
-
before_script:
|
276
|
-
- rm /etc/apt/sources.list.d/jessie-backports.list
|
277
|
-
- apt-key adv --keyserver keyserver.ubuntu.com --recv-keys AA8E81B4331F7F50 7638D0442B90D010 8B48AD6246925553
|
278
|
-
- echo "deb [trusted=yes] http://archive.debian.org/debian/ jessie main contrib non-free" | tee /etc/apt/sources.list
|
279
|
-
- apt-get update # Add UTF-8 support
|
280
|
-
- apt-get install -y locales >/dev/null # |
|
281
|
-
- echo "en_US UTF-8" > /etc/locale.gen # |
|
282
|
-
- locale-gen en_US.UTF-8 # |
|
283
|
-
- export LANG=en_US.UTF-8 # |
|
284
|
-
- export LANGUAGE=en_US:en # |
|
285
|
-
- export LC_ALL=en_US.UTF-8 # v
|
286
|
-
- apt-get install -y git >/dev/null # Add git binary
|
287
|
-
- export JRUBY_OPTS=--dev # Faster test runs
|
288
|
-
- ruby -v # Print out ruby version for debugging
|
289
|
-
- wget https://rubygems.org/downloads/jruby-openssl-0.9.21-java.gem # Needed to support newer ciphers when connecting to rubygems.org (otherwise gem downloads fail)
|
290
|
-
- gem install jruby-openssl-0.9.21-java.gem # Install the newer gem
|
291
|
-
- gem uninstall -x -i /opt/jruby/lib/ruby/gems/shared bundler # Remove any pre-existing bundler
|
292
|
-
- gem install bundler:'< 2' # Install latest bundler 1.x
|
293
|
-
- bundle install -j $(nproc) --path vendor # Install dependencies into ./vendor/ruby
|
294
|
-
|
295
|
-
script:
|
296
|
-
- bin/rspec
|
297
|
-
|
298
|
-
testjruby_9_1:
|
299
|
-
image: "jruby:9.1"
|
300
|
-
|
301
|
-
cache: # Cache gems in between builds
|
302
|
-
paths:
|
303
|
-
- vendor/ruby
|
304
|
-
|
305
|
-
before_script:
|
306
|
-
- apt-get update >/dev/null # Add UTF-8 support
|
307
|
-
- apt-get install -y locales >/dev/null # |
|
308
|
-
- echo "en_US UTF-8" > /etc/locale.gen # |
|
309
|
-
- locale-gen en_US.UTF-8 # |
|
310
|
-
- export LANG=en_US.UTF-8 # |
|
311
|
-
- export LANGUAGE=en_US:en # |
|
312
|
-
- export LC_ALL=en_US.UTF-8 # v
|
313
|
-
- apt-get install -y git >/dev/null # Add git binary
|
314
|
-
- export JRUBY_OPTS=--dev # Faster test runs
|
315
|
-
- ruby -v # Print out ruby version for debugging
|
316
|
-
- gem uninstall -x -i /opt/jruby/lib/ruby/gems/shared bundler # Remove any pre-existing bundler
|
317
|
-
- gem install bundler:'< 2' # Bundler is not installed with the image
|
318
|
-
- bundle install -j $(nproc) --path vendor # Install dependencies into ./vendor/ruby
|
319
|
-
|
320
|
-
script:
|
321
|
-
- bin/rspec
|
322
|
-
|
323
121
|
# This is not repeated from the 9.2 below! 9.2.0.0 is a very specific version with a bug in the Set interoperability so
|
324
122
|
# we'll want to check that our workaround is working with this one even after the 9.2 branch moves on.
|
325
123
|
testjruby9_2_0_0:
|
data/.standard.yml
CHANGED
data/README.adoc
CHANGED
@@ -94,10 +94,10 @@ Beyond being immutable, these data structures are thread-safe, and can be effici
|
|
94
94
|
|
95
95
|
It also (_optionally!_) interoperates with the https://github.com/ruby-concurrency/concurrent-ruby[concurrent-ruby gem], for when you need that extra Oomph (or just thread-safe mutability). See <<concurrent-ruby-interoperability,below>> for more details.
|
96
96
|
|
97
|
-
Underneath the covers, persistent-π mostly builds atop the awesome https://github.com/
|
97
|
+
Underneath the covers, persistent-π mostly builds atop the awesome https://github.com/immutable-ruby/immutable-ruby[immutable-ruby gem].
|
98
98
|
Big thanks to its equally-awesome authors!
|
99
99
|
|
100
|
-
Persistent-π is fully supported and tested on Ruby versions
|
100
|
+
Persistent-π is fully supported and tested on Ruby versions 2.4 to 3.3, JRuby 9.2 to 9.4, and TruffleRuby π.
|
101
101
|
If we don't support your Ruby, it's probably a Python binary instead (or a potato?).
|
102
102
|
Keep calm and π away!
|
103
103
|
|
@@ -258,11 +258,11 @@ my_set = Set.new([:regular, :ruby, :set])
|
|
258
258
|
=> Persistentπ::Set[:regular, :ruby, :set]
|
259
259
|
----
|
260
260
|
|
261
|
-
And it works for https://github.com/hamstergem/hamster[hamster gem] (`Hamster::Vector`, `Hamster::Hash`, `Hamster::Set`) and https://github.com/ruby-concurrency/concurrent-ruby[concurrent-ruby gem] (`Concurrent::Array`, `Concurrent::Tuple`, `Concurrent::Hash`, `Concurrent::Map`) data structures:
|
261
|
+
And it works for https://github.com/hamstergem/hamster[hamster gem] (`Hamster::Vector`, `Hamster::Hash`, `Hamster::Set`), https://github.com/immutable-ruby/immutable-ruby[immutable-ruby gem] (`Immutable::Vector`, `Immutable::Hash`, `Immutable::Set`) and https://github.com/ruby-concurrency/concurrent-ruby[concurrent-ruby gem] (`Concurrent::Array`, `Concurrent::Tuple`, `Concurrent::Hash`, `Concurrent::Map`) data structures:
|
262
262
|
|
263
263
|
[source,ruby]
|
264
264
|
----
|
265
|
-
my_vector =
|
265
|
+
my_vector = Immutable::Vector[1, 2, 3]
|
266
266
|
πify[my_vector]
|
267
267
|
# => Persistentπ::Array[1, 2, 3]
|
268
268
|
|
@@ -275,7 +275,7 @@ my_tuple.set(0, :hello)
|
|
275
275
|
πify[my_tuple]
|
276
276
|
# => Persistentπ::Array[:hello]
|
277
277
|
|
278
|
-
my_hash =
|
278
|
+
my_hash = Immutable::Hash[hello: :world]
|
279
279
|
πify[my_hash]
|
280
280
|
# => Persistentπ::Hash[:hello => :world]
|
281
281
|
|
@@ -288,7 +288,7 @@ my_map[:hello] = :world
|
|
288
288
|
πify[my_map]
|
289
289
|
# => Persistentπ::Hash[:hello => :world]
|
290
290
|
|
291
|
-
my_set =
|
291
|
+
my_set = Immutable::Set[:hello, :world]
|
292
292
|
πify[my_set]
|
293
293
|
# => Persistentπ::Set[:hello, :world]
|
294
294
|
----
|
@@ -418,28 +418,28 @@ my_concurrent_map = my_hash.to_concurrent_map
|
|
418
418
|
|
419
419
|
=== API documentation for the persistent structures
|
420
420
|
|
421
|
-
Because the persistent structures are provided by the awesome https://github.com/
|
421
|
+
Because the persistent structures are provided by the awesome https://github.com/immutable-ruby/immutable-ruby[immutable-ruby gem], you can refer back to immutable-ruby's API docs for details on the operations provided by each data structure.
|
422
422
|
|
423
423
|
==== Array
|
424
424
|
|
425
|
-
Built on top of `
|
425
|
+
Built on top of `Immutable::Vector`
|
426
426
|
|
427
|
-
* https://github.com/
|
428
|
-
*
|
427
|
+
* https://github.com/immutable-ruby/immutable-ruby#vector-api-documentation[Example usage]
|
428
|
+
* https://rubydoc.info/github/immutable-ruby/immutable-ruby/master/Immutable/Vector[API docs]
|
429
429
|
|
430
430
|
==== Hash
|
431
431
|
|
432
|
-
Built on top of `
|
432
|
+
Built on top of `Immutable::Hash`
|
433
433
|
|
434
|
-
* https://github.com/
|
435
|
-
* http://rubydoc.info/github/
|
434
|
+
* https://github.com/immutable-ruby/immutable-ruby#hash-api-documentation[Example usage]
|
435
|
+
* http://rubydoc.info/github/immutable-ruby/immutable-ruby/master/Immutable/Hash[API docs]
|
436
436
|
|
437
437
|
==== Set
|
438
438
|
|
439
|
-
Built on top of `
|
439
|
+
Built on top of `Immutable::Set`
|
440
440
|
|
441
|
-
* https://github.com/
|
442
|
-
* http://
|
441
|
+
* https://github.com/immutable-ruby/immutable-ruby#set-api-documentation[Example usage]
|
442
|
+
* http://rubydoc.info/github/immutable-ruby/immutable-ruby/master/Immutable/Set[API docs]
|
443
443
|
|
444
444
|
== AAARGH YOU FIEND WHY IS THERE AN EMOJI ON MY CODEBASE?
|
445
445
|
|
@@ -504,6 +504,6 @@ Everyone interacting in the Persistent-π projectβs codebases, issue tracker
|
|
504
504
|
|
505
505
|
Interested in immutable/persistent data structures? Here are some interesting resources for your exploration:
|
506
506
|
|
507
|
-
* https://github.com/hamstergem/hamster[hamster gem]
|
508
507
|
* https://github.com/immutable-ruby/immutable-ruby[immmutable-ruby gem]
|
508
|
+
* https://github.com/hamstergem/hamster[hamster gem]
|
509
509
|
* https://gitlab.com/ivoanjo/persistent-dmnd/issues[Your suggestion here]
|
data/UPSTREAM_TODO.adoc
CHANGED
@@ -120,13 +120,3 @@ def <=>(other)
|
|
120
120
|
self == other ? 0 : nil
|
121
121
|
end
|
122
122
|
----
|
123
|
-
|
124
|
-
=== Fix `Hash` comparison with Ruby hashes using `<`/`+++<=+++` breaks on Ruby 2.2 or older
|
125
|
-
|
126
|
-
Because the default implementation of this methods is `other > self` or `other >= self`, this breaks on older rubies as Hash does not implement these methods.
|
127
|
-
|
128
|
-
By relying supplying our own comparison code (similar to `>`/`>=`) we can workaround this.
|
129
|
-
|
130
|
-
=== Fix unneeded complex comparison in `Hash#>`
|
131
|
-
|
132
|
-
Instead of implementing it as `self != other && self >= other` and thus requiring twice the iterations/comparisons, this can just be `self.size > other.size`.
|
data/gems.rb
CHANGED
@@ -1,6 +1,3 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
# typed: false
|
3
|
-
|
4
1
|
source "https://rubygems.org"
|
5
2
|
|
6
3
|
gemspec
|
@@ -8,4 +5,4 @@ gemspec
|
|
8
5
|
# Specify ffi version to avoid dependency issues when switching between MRI
|
9
6
|
# and JRuby with the same gems.lock
|
10
7
|
# Only used in development
|
11
|
-
gem "ffi", "~> 1.
|
8
|
+
gem "ffi", "~> 1.15.5"
|
data/lib/persistent-dmnd.rb
CHANGED
@@ -1,6 +1,3 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
# typed: true
|
3
|
-
|
4
1
|
# Persistent-π: Ruby gem for easily creating immutable data structures
|
5
2
|
# Copyright (c) 2017-2021 Ivo Anjo <ivo@ivoanjo.me>
|
6
3
|
#
|
@@ -35,11 +32,8 @@ require "persistent_dmnd/array"
|
|
35
32
|
require "persistent_dmnd/hash"
|
36
33
|
require "persistent_dmnd/set"
|
37
34
|
require "persistent_dmnd/dmndifier"
|
38
|
-
require "persistent_dmnd/jruby_workaround"
|
39
35
|
|
40
36
|
module Persistentπ
|
41
|
-
include JRubyWorkaround
|
42
|
-
|
43
37
|
def self.included(klass)
|
44
38
|
# Make methods on this module also available inside classes (e.g. not just in instances)
|
45
39
|
klass.extend(self)
|
@@ -103,7 +97,7 @@ module Persistentπ
|
|
103
97
|
# * Converts strings into immutable Strings (without modifying the original String)
|
104
98
|
# * Converts objects that answer to #to_str into frozen Strings
|
105
99
|
# * Converts sets (e.g. something that #is_a?(::Set) or answers to #to_set) into persistent sets
|
106
|
-
# * Converts Hamster and Concurrent (from concurrent-ruby) data structures to their persistent counterparts
|
100
|
+
# * Converts Hamster (from hamster), Immutable and Concurrent (from concurrent-ruby) data structures to their persistent counterparts
|
107
101
|
#
|
108
102
|
def πify
|
109
103
|
Persistentπ::Dmndifier
|
@@ -1,6 +1,3 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
# typed: false
|
3
|
-
|
4
1
|
# Persistent-π: Ruby gem for easily creating immutable data structures
|
5
2
|
# Copyright (c) 2017-2021 Ivo Anjo <ivo@ivoanjo.me>
|
6
3
|
#
|
@@ -33,16 +30,14 @@
|
|
33
30
|
require "persistent_dmnd/self_conversion"
|
34
31
|
require "persistent_dmnd/is_persistent"
|
35
32
|
require "persistent_dmnd/concurrent_ruby_support"
|
36
|
-
require "persistent_dmnd/jruby_workaround"
|
37
33
|
|
38
|
-
require "
|
34
|
+
require "immutable"
|
39
35
|
require "set"
|
40
36
|
|
41
37
|
module Persistentπ
|
42
|
-
class Array <
|
38
|
+
class Array < Immutable::Vector
|
43
39
|
include SelfConversion
|
44
40
|
include IsPersistent
|
45
|
-
include JRubyWorkaround
|
46
41
|
include Persistentπ
|
47
42
|
|
48
43
|
def self.[](*items)
|
@@ -1,6 +1,3 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
# typed: true
|
3
|
-
|
4
1
|
# Persistent-π: Ruby gem for easily creating immutable data structures
|
5
2
|
# Copyright (c) 2017-2021 Ivo Anjo <ivo@ivoanjo.me>
|
6
3
|
#
|
@@ -30,8 +27,6 @@
|
|
30
27
|
|
31
28
|
# frozen_string_literal: true
|
32
29
|
|
33
|
-
require "thread"
|
34
|
-
|
35
30
|
module Persistentπ
|
36
31
|
# Simple module that attempts to load concurrent-ruby, and then stores the result for quick lookup
|
37
32
|
# This way we take care of loading concurrent-ruby ONLY when the library client asks us to, thus not bloating
|
@@ -1,6 +1,3 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
# typed: true
|
3
|
-
|
4
1
|
# Persistent-π: Ruby gem for easily creating immutable data structures
|
5
2
|
# Copyright (c) 2017-2021 Ivo Anjo <ivo@ivoanjo.me>
|
6
3
|
#
|
@@ -30,9 +27,7 @@
|
|
30
27
|
|
31
28
|
# frozen_string_literal: true
|
32
29
|
|
33
|
-
require "
|
34
|
-
|
35
|
-
require "hamster"
|
30
|
+
require "immutable"
|
36
31
|
|
37
32
|
module Persistentπ
|
38
33
|
class Dmndifier
|
@@ -54,7 +49,11 @@ module Persistentπ
|
|
54
49
|
arg.to_dmnd
|
55
50
|
elsif arg.respond_to?(:to_hash)
|
56
51
|
hπ[arg.to_hash]
|
57
|
-
elsif arg.is_a?(
|
52
|
+
elsif arg.is_a?(Immutable::Set) || arg.is_a?(Immutable::SortedSet)
|
53
|
+
sπ[*arg.to_a]
|
54
|
+
elsif defined?(Hamster::Set) && arg.is_a?(Hamster::Set)
|
55
|
+
sπ[*arg.to_a]
|
56
|
+
elsif defined?(Hamster::SortedSet) && arg.is_a?(Hamster::SortedSet)
|
58
57
|
sπ[*arg.to_a]
|
59
58
|
elsif arg.respond_to?(:to_ary)
|
60
59
|
aπ[*arg.to_ary]
|
@@ -63,9 +62,9 @@ module Persistentπ
|
|
63
62
|
elsif arg.respond_to?(:to_set)
|
64
63
|
sπ[*arg.to_set.to_a]
|
65
64
|
elsif defined?(Concurrent::Map) && arg.is_a?(Concurrent::Map)
|
66
|
-
hπ[
|
65
|
+
hπ[arg.enum_for(:each_pair).to_h]
|
67
66
|
elsif arg.respond_to?(:each_pair)
|
68
|
-
hπ[
|
67
|
+
hπ[arg.each_pair.to_h]
|
69
68
|
else
|
70
69
|
options.fetch(:on_unknown).call(arg)
|
71
70
|
end
|
data/lib/persistent_dmnd/hash.rb
CHANGED
@@ -1,6 +1,3 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
# typed: false
|
3
|
-
|
4
1
|
# Persistent-π: Ruby gem for easily creating immutable data structures
|
5
2
|
# Copyright (c) 2017-2021 Ivo Anjo <ivo@ivoanjo.me>
|
6
3
|
#
|
@@ -33,16 +30,14 @@
|
|
33
30
|
require "persistent_dmnd/self_conversion"
|
34
31
|
require "persistent_dmnd/is_persistent"
|
35
32
|
require "persistent_dmnd/concurrent_ruby_support"
|
36
|
-
require "persistent_dmnd/jruby_workaround"
|
37
33
|
|
38
|
-
require "
|
34
|
+
require "immutable"
|
39
35
|
require "set"
|
40
36
|
|
41
37
|
module Persistentπ
|
42
|
-
class Hash <
|
38
|
+
class Hash < Immutable::Hash
|
43
39
|
include SelfConversion
|
44
40
|
include IsPersistent
|
45
|
-
include JRubyWorkaround
|
46
41
|
include Persistentπ
|
47
42
|
|
48
43
|
# Hashes are not arrays and thus should not implement :to_ary
|
@@ -79,26 +74,6 @@ module Persistentπ
|
|
79
74
|
::Set.new(self)
|
80
75
|
end
|
81
76
|
|
82
|
-
def <(other)
|
83
|
-
if size >= other.size
|
84
|
-
false
|
85
|
-
else
|
86
|
-
self <= other
|
87
|
-
end
|
88
|
-
end
|
89
|
-
|
90
|
-
def <=(other)
|
91
|
-
if size > other.size
|
92
|
-
false
|
93
|
-
else
|
94
|
-
each do |key, value|
|
95
|
-
return false if other[key] != value
|
96
|
-
end
|
97
|
-
|
98
|
-
true
|
99
|
-
end
|
100
|
-
end
|
101
|
-
|
102
77
|
# Return each entry as a key, value pair inside an immutable array
|
103
78
|
def eachπ
|
104
79
|
if block_given?
|
@@ -1,6 +1,3 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
# typed: false
|
3
|
-
|
4
1
|
# Persistent-π: Ruby gem for easily creating immutable data structures
|
5
2
|
# Copyright (c) 2017-2021 Ivo Anjo <ivo@ivoanjo.me>
|
6
3
|
#
|
@@ -43,7 +40,7 @@ module Persistentπ
|
|
43
40
|
end
|
44
41
|
end
|
45
42
|
|
46
|
-
if RUBY_PLATFORM == "java" &&
|
43
|
+
if RUBY_PLATFORM == "java" && JRUBY_VERSION.start_with?("9.2.", "9.3.", "9.4.") && workaround_needed?
|
47
44
|
class ::Set
|
48
45
|
# Save existing Set methods
|
49
46
|
|
@@ -1,6 +1,3 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
# typed: true
|
3
|
-
|
4
1
|
# Persistent-π: Ruby gem for easily creating immutable data structures
|
5
2
|
# Copyright (c) 2017-2021 Ivo Anjo <ivo@ivoanjo.me>
|
6
3
|
#
|
@@ -30,13 +27,9 @@
|
|
30
27
|
|
31
28
|
# frozen_string_literal: true
|
32
29
|
|
33
|
-
require "persistent_dmnd/jruby_workaround"
|
34
|
-
|
35
30
|
module Persistentπ
|
36
31
|
# Implements trivial conversion to persistent data structures for our own classes
|
37
32
|
module SelfConversion
|
38
|
-
include JRubyWorkaround
|
39
|
-
|
40
33
|
def to_π
|
41
34
|
self
|
42
35
|
end
|
data/lib/persistent_dmnd/set.rb
CHANGED
@@ -1,6 +1,3 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
# typed: true
|
3
|
-
|
4
1
|
# Persistent-π: Ruby gem for easily creating immutable data structures
|
5
2
|
# Copyright (c) 2017-2021 Ivo Anjo <ivo@ivoanjo.me>
|
6
3
|
#
|
@@ -33,17 +30,15 @@
|
|
33
30
|
require "persistent_dmnd/self_conversion"
|
34
31
|
require "persistent_dmnd/is_persistent"
|
35
32
|
require "persistent_dmnd/concurrent_ruby_support"
|
36
|
-
require "persistent_dmnd/jruby_workaround"
|
37
33
|
require "persistent_dmnd/jruby_9_2_set_workaround"
|
38
34
|
|
39
|
-
require "
|
35
|
+
require "immutable"
|
40
36
|
require "set"
|
41
37
|
|
42
38
|
module Persistentπ
|
43
|
-
class Set <
|
39
|
+
class Set < Immutable::Set
|
44
40
|
include SelfConversion
|
45
41
|
include IsPersistent
|
46
|
-
include JRubyWorkaround
|
47
42
|
include Persistentπ
|
48
43
|
|
49
44
|
def self.from_set(set)
|
@@ -1,6 +1,3 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
# typed: strong
|
3
|
-
|
4
1
|
# Persistent-π: Ruby gem for easily creating immutable data structures
|
5
2
|
# Copyright (c) 2017-2021 Ivo Anjo <ivo@ivoanjo.me>
|
6
3
|
#
|
@@ -31,5 +28,5 @@
|
|
31
28
|
# frozen_string_literal: true
|
32
29
|
|
33
30
|
module Persistentπ
|
34
|
-
VERSION = "
|
31
|
+
VERSION = "3.0.0"
|
35
32
|
end
|
data/persistent-dmnd.gemspec
CHANGED
@@ -1,5 +1,3 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
|
3
1
|
# Persistent-π: Ruby gem for easily creating immutable data structures
|
4
2
|
# Copyright (c) 2017-2021 Ivo Anjo <ivo@ivoanjo.me>
|
5
3
|
#
|
@@ -49,16 +47,18 @@ Gem::Specification.new do |spec|
|
|
49
47
|
end
|
50
48
|
spec.require_paths = ["lib"]
|
51
49
|
|
52
|
-
spec.required_ruby_version = ">=
|
50
|
+
spec.required_ruby_version = ">= 2.4.0"
|
53
51
|
|
54
|
-
spec.add_development_dependency "bundler", "~> 1.
|
55
|
-
spec.add_development_dependency "rake", "~>
|
56
|
-
spec.add_development_dependency "rspec", "~> 3.
|
52
|
+
spec.add_development_dependency "bundler", "~> 1.17" if RUBY_VERSION < "2.6"
|
53
|
+
spec.add_development_dependency "rake", "~> 13.1"
|
54
|
+
spec.add_development_dependency "rspec", "~> 3.13"
|
57
55
|
spec.add_development_dependency "concurrent-ruby", "~> 1.1"
|
58
56
|
spec.add_development_dependency "standard" if RUBY_VERSION >= "2.6.0"
|
59
|
-
spec.add_development_dependency "pry"
|
60
|
-
spec.add_development_dependency "pry-byebug" if RUBY_ENGINE == "ruby"
|
61
|
-
spec.add_development_dependency "pry-debugger-jruby" if RUBY_ENGINE == "jruby"
|
57
|
+
spec.add_development_dependency "pry"
|
58
|
+
spec.add_development_dependency "pry-byebug" if RUBY_ENGINE == "ruby"
|
59
|
+
spec.add_development_dependency "pry-debugger-jruby" if RUBY_ENGINE == "jruby"
|
60
|
+
spec.add_development_dependency "hamster", ">= 3.0.0"
|
61
|
+
spec.add_development_dependency "warning", "~> 1.3.0"
|
62
62
|
|
63
|
-
spec.add_dependency "
|
63
|
+
spec.add_dependency "immutable-ruby", ">= 0.1.0"
|
64
64
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: persistent-dmnd
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 3.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ivo Anjo
|
@@ -16,28 +16,28 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '13.1'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '13.1'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rspec
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '3.
|
33
|
+
version: '3.13'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '3.
|
40
|
+
version: '3.13'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: concurrent-ruby
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -96,18 +96,46 @@ dependencies:
|
|
96
96
|
version: '0'
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
98
|
name: hamster
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: 3.0.0
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: 3.0.0
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: warning
|
99
113
|
requirement: !ruby/object:Gem::Requirement
|
100
114
|
requirements:
|
101
115
|
- - "~>"
|
102
116
|
- !ruby/object:Gem::Version
|
103
|
-
version:
|
104
|
-
type: :
|
117
|
+
version: 1.3.0
|
118
|
+
type: :development
|
105
119
|
prerelease: false
|
106
120
|
version_requirements: !ruby/object:Gem::Requirement
|
107
121
|
requirements:
|
108
122
|
- - "~>"
|
109
123
|
- !ruby/object:Gem::Version
|
110
|
-
version:
|
124
|
+
version: 1.3.0
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: immutable-ruby
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: 0.1.0
|
132
|
+
type: :runtime
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ">="
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: 0.1.0
|
111
139
|
description: A tiny ruby gem that gives you a beautiful short-hand syntax for creating
|
112
140
|
immutable arrays, hashes and sets
|
113
141
|
email: ivo@ivoanjo.me
|
@@ -137,8 +165,6 @@ files:
|
|
137
165
|
- lib/persistent_dmnd/hash.rb
|
138
166
|
- lib/persistent_dmnd/is_persistent.rb
|
139
167
|
- lib/persistent_dmnd/jruby_9_2_set_workaround.rb
|
140
|
-
- lib/persistent_dmnd/jruby_workaround.rb
|
141
|
-
- lib/persistent_dmnd/ruby_1_9_and_2_0_support.rb
|
142
168
|
- lib/persistent_dmnd/self_conversion.rb
|
143
169
|
- lib/persistent_dmnd/set.rb
|
144
170
|
- lib/persistent_dmnd/version.rb
|
@@ -155,14 +181,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
155
181
|
requirements:
|
156
182
|
- - ">="
|
157
183
|
- !ruby/object:Gem::Version
|
158
|
-
version:
|
184
|
+
version: 2.4.0
|
159
185
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
160
186
|
requirements:
|
161
187
|
- - ">="
|
162
188
|
- !ruby/object:Gem::Version
|
163
189
|
version: '0'
|
164
190
|
requirements: []
|
165
|
-
rubygems_version: 3.
|
191
|
+
rubygems_version: 3.5.3
|
166
192
|
signing_key:
|
167
193
|
specification_version: 4
|
168
194
|
summary: "Persistent-\U0001F48E: Because Immutable Data Is Forever"
|
@@ -1,107 +0,0 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
# typed: false
|
3
|
-
|
4
|
-
# Persistent-π: Ruby gem for easily creating immutable data structures
|
5
|
-
# Copyright (c) 2017-2021 Ivo Anjo <ivo@ivoanjo.me>
|
6
|
-
#
|
7
|
-
# This file is part of Persistent-π.
|
8
|
-
#
|
9
|
-
# MIT License
|
10
|
-
#
|
11
|
-
# Copyright (c) 2017-2021 Ivo Anjo
|
12
|
-
#
|
13
|
-
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
14
|
-
# of this software and associated documentation files (the "Software"), to deal
|
15
|
-
# in the Software without restriction, including without limitation the rights
|
16
|
-
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
17
|
-
# copies of the Software, and to permit persons to whom the Software is
|
18
|
-
# furnished to do so, subject to the following conditions:
|
19
|
-
#
|
20
|
-
# The above copyright notice and this permission notice shall be included in all
|
21
|
-
# copies or substantial portions of the Software.
|
22
|
-
#
|
23
|
-
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
24
|
-
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
25
|
-
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
26
|
-
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
27
|
-
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
28
|
-
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
29
|
-
# SOFTWARE.
|
30
|
-
|
31
|
-
# frozen_string_literal: true
|
32
|
-
|
33
|
-
module Persistentπ
|
34
|
-
module JRubyWorkaround
|
35
|
-
if RUBY_PLATFORM == "java" && JRUBY_VERSION < "9.2.0.0" # Only supposed to do something on legacy JRuby versions
|
36
|
-
BROKEN_ENCODING = "\x00"
|
37
|
-
private_constant :BROKEN_ENCODING
|
38
|
-
|
39
|
-
BROKEN_ENCODING_JRUBY_1_7 = [239, 146, 142].pack("c*").force_encoding("UTF-8")
|
40
|
-
private_constant :BROKEN_ENCODING_JRUBY_1_7
|
41
|
-
|
42
|
-
def self.included(klass)
|
43
|
-
# Make methods on this module also available inside classes (e.g. not just in instances)
|
44
|
-
klass.extend(self)
|
45
|
-
end
|
46
|
-
|
47
|
-
def method_added(name)
|
48
|
-
super
|
49
|
-
maybe_fix_broken_encoding(name)
|
50
|
-
end
|
51
|
-
|
52
|
-
def singleton_method_added(name)
|
53
|
-
super
|
54
|
-
maybe_fix_broken_encoding(name, singleton_class)
|
55
|
-
end
|
56
|
-
|
57
|
-
private
|
58
|
-
|
59
|
-
# Workaround JRuby encoding bug
|
60
|
-
# See https://github.com/jruby/jruby/issues/4878
|
61
|
-
# and https://gitlab.com/ivoanjo/persistent-dmnd/issues/5
|
62
|
-
#
|
63
|
-
# The trick here is that on JRuby, methods with emojis in the name are defined, but the resulting name is mangled
|
64
|
-
# so instead of for instance #to_π the result is #to_?\x00. (Or #πify will become #?ify\x00.) This behavior is
|
65
|
-
# consistent between def and calling a method, so def will register a method #to_?\x00, and a normal method call
|
66
|
-
# will do the same mangling and thus look for a method **WITH** the mangled name.
|
67
|
-
#
|
68
|
-
# But there are still other places in the code that rely on the correct name, such as alias and public_send/send,
|
69
|
-
# so we additionally use this module to define the correct name as an alias for the broken name.
|
70
|
-
#
|
71
|
-
# Thus, it all works on JRuby, albeit in a very roundabout way!
|
72
|
-
#
|
73
|
-
# FOR JRUBY 1.7:
|
74
|
-
# On JRuby 1.7 it seems that the mangling is different, and the emoji just gets replaced with ?, so for
|
75
|
-
# instance #to_π becomes #to_?. But then, to make things interesting, on symbols created without quotes, it
|
76
|
-
# gets mangled with the BROKEN_ENCODING_JRUBY_1_7, e.g :to_π becomes :to_BROKEN_ENCODING_JRUBY_1_7 (but
|
77
|
-
# :"to_π" is still correct).
|
78
|
-
# To support both of these, we add an extra alias on JRuby, so that everything else seems to work even if it is
|
79
|
-
# actually using the name with the mangled encoding.
|
80
|
-
#
|
81
|
-
def maybe_fix_broken_encoding(name, target = nil)
|
82
|
-
name_string = name.to_s
|
83
|
-
|
84
|
-
if JRUBY_VERSION.start_with?("1.7.")
|
85
|
-
unless name_string.match(/\?.+/) ||
|
86
|
-
["a?", "h?", "s?", "each?"].include?(name_string) ||
|
87
|
-
["_?", "_a?", "_h?", "_s?"].any? { |suffix| name_string.end_with?(suffix) }
|
88
|
-
return
|
89
|
-
end
|
90
|
-
else
|
91
|
-
return unless name_string.end_with?(BROKEN_ENCODING)
|
92
|
-
end
|
93
|
-
|
94
|
-
fixed_name = name_string.sub("?", "π").delete(BROKEN_ENCODING).to_sym
|
95
|
-
fixed_name_jruby_1_7 = name_string.sub("?", BROKEN_ENCODING_JRUBY_1_7).to_sym
|
96
|
-
|
97
|
-
if target
|
98
|
-
target.instance_eval { alias_method(fixed_name, name) }
|
99
|
-
target.instance_eval { alias_method(fixed_name_jruby_1_7, name) } if JRUBY_VERSION.start_with?("1.7.")
|
100
|
-
else
|
101
|
-
alias_method(fixed_name, name)
|
102
|
-
alias_method(fixed_name_jruby_1_7, name) if JRUBY_VERSION.start_with?("1.7.")
|
103
|
-
end
|
104
|
-
end
|
105
|
-
end
|
106
|
-
end
|
107
|
-
end
|
@@ -1,48 +0,0 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
# typed: true
|
3
|
-
|
4
|
-
# Persistent-π: Ruby gem for easily creating immutable data structures
|
5
|
-
# Copyright (c) 2017-2021 Ivo Anjo <ivo@ivoanjo.me>
|
6
|
-
#
|
7
|
-
# This file is part of Persistent-π.
|
8
|
-
#
|
9
|
-
# MIT License
|
10
|
-
#
|
11
|
-
# Copyright (c) 2017-2021 Ivo Anjo
|
12
|
-
#
|
13
|
-
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
14
|
-
# of this software and associated documentation files (the "Software"), to deal
|
15
|
-
# in the Software without restriction, including without limitation the rights
|
16
|
-
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
17
|
-
# copies of the Software, and to permit persons to whom the Software is
|
18
|
-
# furnished to do so, subject to the following conditions:
|
19
|
-
#
|
20
|
-
# The above copyright notice and this permission notice shall be included in all
|
21
|
-
# copies or substantial portions of the Software.
|
22
|
-
#
|
23
|
-
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
24
|
-
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
25
|
-
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
26
|
-
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
27
|
-
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
28
|
-
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
29
|
-
# SOFTWARE.
|
30
|
-
|
31
|
-
# frozen_string_literal: true
|
32
|
-
|
33
|
-
module Persistentπ
|
34
|
-
module Ruby19And20Support
|
35
|
-
# Enumerable#to_h was only introduced in Ruby 2.1 so we have to do it by hand on 2.0/1.9
|
36
|
-
if RUBY_VERSION.start_with?("2.0.") || RUBY_VERSION.start_with?("1.9.")
|
37
|
-
def self.enumerable_to_h(enumerable)
|
38
|
-
enumerable.each_with_object({}) do |(key, value), result|
|
39
|
-
result[key] = value
|
40
|
-
end
|
41
|
-
end
|
42
|
-
else
|
43
|
-
def self.enumerable_to_h(enumerable)
|
44
|
-
enumerable.to_h
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|