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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2f13ebbaab7d74cd58d37678b5f294c7ffc8e499
4
- data.tar.gz: e4edd192a82271406e6554bf827f2acfddf3270f
3
+ metadata.gz: d37431f3cf10477e65f24dfee6b9076fb4969810
4
+ data.tar.gz: 010efad274ba249ce67ec414748cd7dd356cb659
5
5
  SHA512:
6
- metadata.gz: b1645e158efb710ce7db7ce75baeda1873b9a5b64e464fb86c58d33e73ed08004db40bd0d7090621a9deb205bd9b6ac595522083642cdd11eb6f24d6c4c7d591
7
- data.tar.gz: 9c6a60b447ab61653366bc05b39cbe172a2c18748c5bdf0bee86b2de59a8238e4121a7ca6aeb1e564168e45d9164ac3b803ede593640cdb825ea6e3fa2f1729a
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.2"
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[expr] while test[expr]
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
@@ -1,5 +1,11 @@
1
1
  require_relative "../mll"
2
2
 
3
+ class Object
4
+ def nest_while_list f, test
5
+ MLL::nest_while_list[self, f, test]
6
+ end
7
+ end
8
+
3
9
  class Array
4
10
  def most
5
11
  MLL::most[self]
@@ -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.2
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-07-25 00:00:00.000000000 Z
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: