obfusk 0.1.2 → 0.1.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: 4c4bd6bb10352b9c18b779e647b5acfd1c3877db
4
- data.tar.gz: c6f6309c765f5c519e155286323bbbb9d82590ff
3
+ metadata.gz: 0f4396e13f93674f41f52a609ececa143d3e23d7
4
+ data.tar.gz: f4ecb55606714316e9cc945a275bf03a764ba2e2
5
5
  SHA512:
6
- metadata.gz: a4dbae8abf373e372b28bbba4b913e2afcc6045c0f4a2480dc8164fabcdbeaee09685530075828bf2b35de45ba62145c7f7b5f2d0769d5141edbd2cbf4b611e4
7
- data.tar.gz: d404720017b40471a4c8abf19ccf6e2ee5261fbe1f43d3763e88992d027b5af3148911a0f6a92ec171917c293087aa33276e16d4ad66bcef68bb53dd55e1152f
6
+ metadata.gz: 167666500dd24a71c3191c0f9f5564c532e89833426beb37a6d27d2d20b78e1a0d942c88b41a172ebfc896d5cb9d3288f666adeee8b6ab02491ae885b80d22c0
7
+ data.tar.gz: 295e1599275dfef6e1b9e32957e58584ff5b27a28b8a0054824acbf74c8dd373f682710fd3d8cbfa45d2d1a24e10ee295726c57826fda1310249ab16e9173ce5
data/README.md CHANGED
@@ -5,7 +5,7 @@
5
5
  Date : 2014-06-18
6
6
 
7
7
  Copyright : Copyright (C) 2014 Felix C. Stegerman
8
- Version : v0.1.2
8
+ Version : v0.1.3
9
9
 
10
10
  []: }}}1
11
11
 
@@ -16,6 +16,7 @@
16
16
  obfusk.rb - functional programming library for ruby
17
17
 
18
18
  ## Examples
19
+
19
20
  []: {{{1
20
21
 
21
22
  ```ruby
@@ -37,6 +38,10 @@ x.match Bar: -> (_) { "it's a bar!" },
37
38
  # => "it's a bar!"
38
39
  ```
39
40
 
41
+ []: }}}1
42
+
43
+ []: {{{1
44
+
40
45
  ```ruby
41
46
  require 'obfusk/atom'
42
47
 
@@ -46,6 +51,32 @@ x._ # => 42
46
51
  x._ # => 53
47
52
  ```
48
53
 
54
+ []: }}}1
55
+
56
+ []: {{{1
57
+
58
+ ```ruby
59
+ require 'obfusk/data'
60
+
61
+ Obfusk.merge([1,2,3], 1 => 99)
62
+ # => [1,99,3]
63
+
64
+ x = { x: { y: 0 }, z: [1,2,3] }
65
+
66
+ Obfusk.get_in x, :x, :y
67
+ # => 0
68
+
69
+ Obfusk.modify_in(x, :x, :y) { |v| v + 1 }
70
+ # => { x: { y: 1 }, z: [1,2,3] }
71
+
72
+ Obfusk.set_in(x, :z, 1, 99)
73
+ # => { x: { y: 0 }, z: [1,99,3] }
74
+ ```
75
+
76
+ []: }}}1
77
+
78
+ []: {{{1
79
+
49
80
  ```ruby
50
81
  require 'obfusk/lazy'
51
82
 
@@ -60,6 +91,10 @@ z._ # => 42 (.new and .value not run until now)
60
91
  Obfusk.eager(lazy_or_not) # => value
61
92
  ```
62
93
 
94
+ []: }}}1
95
+
96
+ []: {{{1
97
+
63
98
  ```ruby
64
99
  require 'obfusk/list'
65
100
 
@@ -75,6 +110,10 @@ fibs.map { |x| x*x } .take(10).to_a
75
110
  # => [0, 1, 1, 4, 9, 25, 64, 169, 441, 1156]
76
111
  ```
77
112
 
113
+ []: }}}1
114
+
115
+ []: {{{1
116
+
78
117
  ```ruby
79
118
  require 'obfusk/monad'
80
119
 
@@ -94,6 +133,10 @@ g = -> y { '...' }
94
133
  Foo.new('...').pipeline f, g
95
134
  ```
96
135
 
136
+ []: }}}1
137
+
138
+ []: {{{1
139
+
97
140
  ```ruby
98
141
  require 'obfusk/monads'
99
142
  ms = Obfusk::Monads
@@ -108,14 +151,15 @@ ms.Left "oops"
108
151
  ms.Right 37
109
152
  ```
110
153
 
111
- ...
112
-
113
154
  []: }}}1
114
155
 
156
+ ...
157
+
115
158
  ## Specs & Docs
116
159
 
117
160
  ```bash
118
161
  $ rake spec
162
+ $ rake coverage
119
163
  $ rake docs
120
164
  ```
121
165
 
data/Rakefile CHANGED
@@ -13,6 +13,11 @@ task 'spec:less' do
13
13
  sh 'rspec -cfd --tty | less -R'
14
14
  end
15
15
 
16
+ desc 'Run specs w/ coverage'
17
+ task :coverage do
18
+ ENV['COVERAGE'] = 'yes'; Rake::Task['spec'].execute
19
+ end
20
+
16
21
  desc 'Check for warnings'
17
22
  task :warn do
18
23
  sh 'ruby -w -I lib -r obfusk -e ""' # TODO
@@ -41,7 +46,7 @@ end
41
46
 
42
47
  desc 'Cleanup'
43
48
  task :clean do
44
- sh 'rm -rf .yardoc/ doc/ *.gem'
49
+ sh 'rm -rf .yardoc/ coverage/ doc/ *.gem'
45
50
  end
46
51
 
47
52
  desc 'Build SNAPSHOT gem'
data/lib/obfusk.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require 'obfusk/adt'
2
2
  require 'obfusk/atom'
3
+ require 'obfusk/data'
3
4
  require 'obfusk/lazy'
4
5
  require 'obfusk/list'
5
6
  require 'obfusk/monad'
@@ -0,0 +1,85 @@
1
+ # -- ; {{{1
2
+ #
3
+ # File : obfusk/data.rb
4
+ # Maintainer : Felix C. Stegerman <flx@obfusk.net>
5
+ # Date : 2014-06-18
6
+ #
7
+ # Copyright : Copyright (C) 2014 Felix C. Stegerman
8
+ # Licence : LGPLv3+
9
+ #
10
+ # -- ; }}}1
11
+
12
+ nil
13
+
14
+ class Array
15
+ # merge array; see Obfusk.merge
16
+ def __obfusk_merge__(h = {})
17
+ dup.__obfusk_merge__! h
18
+ end
19
+
20
+ # merge! array; see Obfusk.merge
21
+ def __obfusk_merge__!(h = {})
22
+ h.each_pair { |k,v| self[k] = v }; self
23
+ end
24
+ end
25
+
26
+ module Obfusk
27
+ # -- data structures --
28
+
29
+ # merge anything that responds to `.__obfusk_merge__` or `.merge`
30
+ def self.merge(x, h = {})
31
+ x.respond_to?(:__obfusk_merge__) ? x.__obfusk_merge__(h) : x.merge(h)
32
+ end
33
+
34
+ # merge anything that responds to `.__obfusk_merge__!` or `.merge!`
35
+ def self.merge!(x, h = {})
36
+ x.respond_to?(:__obfusk_merge__!) ? x.__obfusk_merge__!(h) : x.merge!(h)
37
+ end
38
+
39
+ # -- nested data structures --
40
+
41
+ # get nested key in nested datastructure
42
+ def self.get_in(o, *ks, &b)
43
+ ks.each { |k| o = o.fetch(k) { return b ? b[] : nil } }; o
44
+ end
45
+
46
+ # swap value for nested key in nested datastructure; autovivifies
47
+ # missing keys as hashes
48
+ # @return a new datastructure
49
+ def self.modify_in(o, k, *ks, &b)
50
+ ks_ = [k] + ks; os = nested_objects o, *ks_; o_ = b[os.pop]
51
+ ks_.reverse.each { |k| o_ = merge(os.pop, k => o_) }; o_
52
+ end
53
+
54
+ # swap value for nested key in nested datastructure; autovivifies
55
+ # missing keys as hashes
56
+ # @return modified datastructure
57
+ def self.modify_in!(o, k, *ks, &b)
58
+ ks_ = [k] + ks; os = nested_objects o, *ks_; o_ = b[os.pop]
59
+ ks_.reverse.each { |k| o_ = merge!(os.pop, k => o_) }; o_
60
+ end
61
+
62
+ # get stack of objects for nested key in nested datastructure;
63
+ # autovivifies missing keys as hashes
64
+ def self.nested_objects(o, *ks)
65
+ [o] + ks.map { |k| o = o.fetch(k) { {} } }
66
+ end
67
+
68
+ # set value for nested key in nested datastructure
69
+ # @return a new datastructure
70
+ def self.set_in(o, *ks, v)
71
+ modify_in(o, *ks) { |_| v }
72
+ end
73
+
74
+ # set value for nested key in nested datastructure
75
+ # @return modified datastructure
76
+ def self.set_in!(o, *ks, v)
77
+ modify_in!(o, *ks) { |_| v }
78
+ end
79
+
80
+ # -- ... --
81
+
82
+ # ...
83
+ end
84
+
85
+ # vim: set tw=70 sw=2 sts=2 et fdm=marker :
data/lib/obfusk/lazy.rb CHANGED
@@ -2,13 +2,15 @@
2
2
  #
3
3
  # File : obfusk/lazy.rb
4
4
  # Maintainer : Felix C. Stegerman <flx@obfusk.net>
5
- # Date : 2014-06-17
5
+ # Date : 2014-06-18
6
6
  #
7
7
  # Copyright : Copyright (C) 2014 Felix C. Stegerman
8
8
  # Licence : LGPLv3+
9
9
  #
10
10
  # -- ; }}}1
11
11
 
12
+ nil
13
+
12
14
  module Obfusk
13
15
  # lazy evaluation (thunk)
14
16
  def self.lazy(x = nil, &b)
@@ -1,4 +1,4 @@
1
1
  module Obfusk
2
- VERSION = '0.1.2'
2
+ VERSION = '0.1.3'
3
3
  DATE = '2014-06-18'
4
4
  end
data/obfusk.gemspec CHANGED
@@ -22,6 +22,7 @@ Gem::Specification.new do |s|
22
22
 
23
23
  s.add_development_dependency 'rake'
24
24
  s.add_development_dependency 'rspec'
25
+ s.add_development_dependency 'simplecov', '~> 0.7.1'
25
26
  s.add_development_dependency 'yard'
26
27
 
27
28
  s.required_ruby_version = '>= 1.9.1'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: obfusk
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Felix C. Stegerman
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: simplecov
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 0.7.1
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 0.7.1
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: yard
43
57
  requirement: !ruby/object:Gem::Requirement
@@ -66,6 +80,7 @@ files:
66
80
  - lib/obfusk.rb
67
81
  - lib/obfusk/adt.rb
68
82
  - lib/obfusk/atom.rb
83
+ - lib/obfusk/data.rb
69
84
  - lib/obfusk/lazy.rb
70
85
  - lib/obfusk/list.rb
71
86
  - lib/obfusk/monad.rb