mll 2.6.2 → 2.6.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/TODO.md +9 -2
- data/lib/mll.rb +11 -3
- data/lib/mll/core_ext.rb +6 -0
- data/spec/_spec.rb +30 -2
- metadata +3 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d37431f3cf10477e65f24dfee6b9076fb4969810
|
4
|
+
data.tar.gz: 010efad274ba249ce67ec414748cd7dd356cb659
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8636fc22ee9cade5fe9eb39f88526872ed66714fc43fccb26afd169271baa122ce0844e95429402fcbf3a2c847e452f92a27f1e74451494a78546493625e25b8
|
7
|
+
data.tar.gz: 10a02174cac7729d1c42cbe11a30e2fbe8f33b4d162a0ac3be084c669ec8d9df55601b854a34f8843a85fbf1971be954ba008bf5c0ef69541b1b335cb98993f0
|
data/TODO.md
CHANGED
@@ -8,8 +8,6 @@ module MLL
|
|
8
8
|
enumerator = Enumerator.new do |e|
|
9
9
|
while list.all?{ |i| i.respond_to? :each } &&
|
10
10
|
# TODO refactor into depth-first yielding
|
11
|
-
def nest_while
|
12
|
-
# TODO finish me
|
13
11
|
def fold_list
|
14
12
|
lambda do |x, list, f = nil|
|
15
13
|
# TODO use Ruby#inject ?
|
@@ -103,6 +101,15 @@ describe MLL do
|
|
103
101
|
# TODO example "find the next twin prime after 888" do
|
104
102
|
describe "Properties & Relations:" do
|
105
103
|
# TODO "#nest_while can be expressed in terms of a while loop" do
|
104
|
+
describe "#nest_while_list" do
|
105
|
+
describe "Details:" do
|
106
|
+
# TODO: "NestWhileList[f,expr,test,m] does not start applying test until at least m results have been generated. »"
|
107
|
+
# TODO: "NestWhileList[f,expr,test,m] is equivalent to NestWhileList[f,expr,test,{m,m}]. »"
|
108
|
+
# TODO: "NestWhileList[f,expr,UnsameQ,2] is equivalent to FixedPointList[f,expr]. »"
|
109
|
+
# TODO: "NestWhileList[f,expr,UnsameQ,All] goes on applying f until the same result first appears more than once."
|
110
|
+
# TODO: "NestWhileList[f,expr,test,m,max,n] applies f an extra n times, appending the results to the list generated. »"
|
111
|
+
# TODO: "NestWhileList[f,expr,test,m,max,-n] drops the last n elements from the list generated. »"
|
112
|
+
# TODO A LOT
|
106
113
|
describe "Numerical Data" do
|
107
114
|
describe "#mean" do
|
108
115
|
# TODO examples to README.md
|
data/lib/mll.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
module MLL
|
2
2
|
|
3
|
-
VERSION = "2.6.
|
3
|
+
VERSION = "2.6.3"
|
4
4
|
|
5
5
|
class << self
|
6
6
|
|
@@ -52,13 +52,21 @@ module MLL
|
|
52
52
|
end
|
53
53
|
|
54
54
|
def nest_while
|
55
|
-
# TODO finish me
|
56
55
|
lambda do |expr, f, test|
|
57
|
-
expr = f
|
56
|
+
expr = f.call expr while test.call expr
|
58
57
|
expr
|
59
58
|
end
|
60
59
|
end
|
61
60
|
|
61
|
+
def nest_while_list
|
62
|
+
lambda do |expr, f, test|
|
63
|
+
Enumerator.new do |e|
|
64
|
+
e << expr
|
65
|
+
e << expr = f.call(expr) while test.call expr
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
62
70
|
def fold_list
|
63
71
|
lambda do |x, list, f = nil|
|
64
72
|
unless f
|
data/lib/mll/core_ext.rb
CHANGED
data/spec/_spec.rb
CHANGED
@@ -1007,6 +1007,33 @@ describe MLL do
|
|
1007
1007
|
|
1008
1008
|
end
|
1009
1009
|
|
1010
|
+
# http://reference.wolfram.com/language/ref/NestWhileList.html
|
1011
|
+
describe "#nest_while_list" do
|
1012
|
+
|
1013
|
+
describe "Details:" do
|
1014
|
+
|
1015
|
+
# TODO: "NestWhileList[f,expr,test,m] does not start applying test until at least m results have been generated. »"
|
1016
|
+
# TODO: "NestWhileList[f,expr,test,m] is equivalent to NestWhileList[f,expr,test,{m,m}]. »"
|
1017
|
+
# TODO: "NestWhileList[f,expr,UnsameQ,2] is equivalent to FixedPointList[f,expr]. »"
|
1018
|
+
# TODO: "NestWhileList[f,expr,UnsameQ,All] goes on applying f until the same result first appears more than once."
|
1019
|
+
# TODO: "NestWhileList[f,expr,test,m,max,n] applies f an extra n times, appending the results to the list generated. »"
|
1020
|
+
# TODO: "NestWhileList[f,expr,test,m,max,-n] drops the last n elements from the list generated. »"
|
1021
|
+
|
1022
|
+
end
|
1023
|
+
|
1024
|
+
describe "Basic Examples:" do
|
1025
|
+
|
1026
|
+
example "keep dividing by 2 until the result is no longer an even number" do
|
1027
|
+
expect(nest_while_list[123456, ->(i){ i / 2 }, ->(i){ i.even? }]).to be_a Enumerator
|
1028
|
+
expect(nest_while_list[123456, ->(i){ i / 2 }, ->(i){ i.even? }].to_a).to eq [123456, 61728, 30864, 15432, 7716, 3858, 1929]
|
1029
|
+
end
|
1030
|
+
|
1031
|
+
end
|
1032
|
+
|
1033
|
+
# TODO A LOT
|
1034
|
+
|
1035
|
+
end
|
1036
|
+
|
1010
1037
|
end
|
1011
1038
|
|
1012
1039
|
end
|
@@ -1352,8 +1379,9 @@ describe "core_ext" do
|
|
1352
1379
|
example "after core_ext required" do
|
1353
1380
|
require_relative "../lib/mll/core_ext"
|
1354
1381
|
aggregate_failures "everything is fine" do
|
1355
|
-
expect([1,2,3,4].most).to eq [1,2,3]
|
1356
|
-
|
1382
|
+
expect( [1,2,3,4].most ).to eq [1,2,3]
|
1383
|
+
expect( [1,2,3,4].rest.to_a ).to eq [2,3,4]
|
1384
|
+
expect( 123456.nest_while_list(->(i){ i / 2 }, ->(i){ i.even? }).to_a ).to eq [123456, 61728, 30864, 15432, 7716, 3858, 1929]
|
1357
1385
|
end
|
1358
1386
|
end
|
1359
1387
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mll
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.6.
|
4
|
+
version: 2.6.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Victor Maslov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-12-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -76,9 +76,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
76
76
|
version: '0'
|
77
77
|
requirements: []
|
78
78
|
rubyforge_project:
|
79
|
-
rubygems_version: 2.0.14
|
79
|
+
rubygems_version: 2.0.14.1
|
80
80
|
signing_key:
|
81
81
|
specification_version: 4
|
82
82
|
summary: Mathematica Language Library in Ruby
|
83
83
|
test_files: []
|
84
|
-
has_rdoc:
|