mug 0.0.8 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/mug.rb +13 -12
- data/lib/mug/and-or.rb +48 -48
- data/lib/mug/apply.rb +58 -0
- data/lib/mug/bool.rb +128 -128
- data/lib/mug/fragile-method-chain.rb +70 -70
- data/lib/mug/hashmap.rb +100 -100
- data/lib/mug/hashop.rb +54 -54
- data/lib/mug/iterator.rb +2 -2
- data/lib/mug/iterator/for.rb +29 -29
- data/lib/mug/iterator/method.rb +29 -29
- data/lib/mug/iterator_c.rb +44 -44
- data/lib/mug/maybe.rb +59 -59
- data/lib/mug/self.rb +33 -33
- data/lib/mug/tau.rb +44 -44
- data/lib/mug/to_h.rb +44 -44
- data/test/test-and-or.rb +41 -41
- data/test/test-bool.rb +70 -70
- data/test/test-fragile-method-chain.rb +65 -65
- data/test/test-hashmap.rb +24 -24
- data/test/test-hashop.rb +62 -62
- data/test/test-iterator-for.rb +18 -18
- data/test/test-iterator-method.rb +18 -18
- data/test/test-maybe.rb +90 -90
- data/test/test-self.rb +13 -13
- data/test/test-tau.rb +22 -22
- data/test/test-to_h.rb +16 -15
- data/test/test_apply.rb +56 -0
- metadata +28 -25
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: caac6c79133f87c320e088fe7273c80e440a00e1
|
4
|
+
data.tar.gz: 25ba29b491cdaf310e65803e854fefd855df6120
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7268ec06de0aff1c765b3e911e577746fbdd17a2c8b198e0c99fcd76a0e46530a4d4829c4b3cde41b5188f916548ec273c00c9c828e705f508d2dabcc241a305
|
7
|
+
data.tar.gz: 728948939a043370bd502776f4905387afab60224ccee6b1e03cf1eef96bd4f66ab9cfab3b60921139e7253283091d8fee40f9f1d8259dd09c239f1c3baa2567
|
data/lib/mug.rb
CHANGED
@@ -1,12 +1,13 @@
|
|
1
|
-
|
2
|
-
require_relative 'mug/
|
3
|
-
require_relative 'mug/
|
4
|
-
require_relative 'mug/
|
5
|
-
require_relative 'mug/
|
6
|
-
require_relative 'mug/
|
7
|
-
require_relative 'mug/iterator/
|
8
|
-
require_relative 'mug/
|
9
|
-
require_relative 'mug/
|
10
|
-
require_relative 'mug/
|
11
|
-
require_relative 'mug/
|
12
|
-
|
1
|
+
|
2
|
+
require_relative 'mug/apply'
|
3
|
+
require_relative 'mug/bool'
|
4
|
+
require_relative 'mug/fragile-method-chain'
|
5
|
+
require_relative 'mug/hashmap'
|
6
|
+
require_relative 'mug/hashop'
|
7
|
+
require_relative 'mug/iterator/for'
|
8
|
+
require_relative 'mug/iterator/method'
|
9
|
+
require_relative 'mug/maybe'
|
10
|
+
require_relative 'mug/self'
|
11
|
+
require_relative 'mug/tau'
|
12
|
+
require_relative 'mug/to_h'
|
13
|
+
|
data/lib/mug/and-or.rb
CHANGED
@@ -1,48 +1,48 @@
|
|
1
|
-
|
2
|
-
class Object
|
3
|
-
|
4
|
-
#
|
5
|
-
# Returns either +obj+ or +default+, depending on the falsiness of +obj+.
|
6
|
-
#
|
7
|
-
# If a block is given, +obj+ is yielded to it; if it returns truthy,
|
8
|
-
# +default+ is returned, otherwise +obj+ is returned.
|
9
|
-
#
|
10
|
-
def and default
|
11
|
-
if block_given?
|
12
|
-
yield(self) ? default : self
|
13
|
-
else
|
14
|
-
self && default
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
#
|
19
|
-
# Returns either +obj+ or +default+, depending on the truthiness of +obj+.
|
20
|
-
#
|
21
|
-
# If a block is given, +obj+ is yielded to it; if it returns truthy,
|
22
|
-
# +obj+ is returned, otherwise +default+ is returned.
|
23
|
-
#
|
24
|
-
def or default
|
25
|
-
if block_given?
|
26
|
-
yield(self) ? self : default
|
27
|
-
else
|
28
|
-
self || default
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
=begin
|
34
|
-
Copyright (c) 2013, Matthew Kerwin <matthew@kerwin.net.au>
|
35
|
-
|
36
|
-
Permission to use, copy, modify, and/or distribute this software for any
|
37
|
-
purpose with or without fee is hereby granted, provided that the above
|
38
|
-
copyright notice and this permission notice appear in all copies.
|
39
|
-
|
40
|
-
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
41
|
-
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
42
|
-
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
43
|
-
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
44
|
-
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
45
|
-
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
46
|
-
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
47
|
-
=end
|
48
|
-
|
1
|
+
|
2
|
+
class Object
|
3
|
+
|
4
|
+
#
|
5
|
+
# Returns either +obj+ or +default+, depending on the falsiness of +obj+.
|
6
|
+
#
|
7
|
+
# If a block is given, +obj+ is yielded to it; if it returns truthy,
|
8
|
+
# +default+ is returned, otherwise +obj+ is returned.
|
9
|
+
#
|
10
|
+
def and default
|
11
|
+
if block_given?
|
12
|
+
yield(self) ? default : self
|
13
|
+
else
|
14
|
+
self && default
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
#
|
19
|
+
# Returns either +obj+ or +default+, depending on the truthiness of +obj+.
|
20
|
+
#
|
21
|
+
# If a block is given, +obj+ is yielded to it; if it returns truthy,
|
22
|
+
# +obj+ is returned, otherwise +default+ is returned.
|
23
|
+
#
|
24
|
+
def or default
|
25
|
+
if block_given?
|
26
|
+
yield(self) ? self : default
|
27
|
+
else
|
28
|
+
self || default
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
=begin
|
34
|
+
Copyright (c) 2013, Matthew Kerwin <matthew@kerwin.net.au>
|
35
|
+
|
36
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
37
|
+
purpose with or without fee is hereby granted, provided that the above
|
38
|
+
copyright notice and this permission notice appear in all copies.
|
39
|
+
|
40
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
41
|
+
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
42
|
+
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
43
|
+
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
44
|
+
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
45
|
+
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
46
|
+
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
47
|
+
=end
|
48
|
+
|
data/lib/mug/apply.rb
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
|
2
|
+
class Proc
|
3
|
+
#
|
4
|
+
# Curries this Proc and partially applies parameters.
|
5
|
+
# If a sufficient number of arguments are supplied, it passes the
|
6
|
+
# supplied arguments to the original proc and returns the result.
|
7
|
+
# Otherwise, returns another curried proc that takes the rest of
|
8
|
+
# arguments.
|
9
|
+
#
|
10
|
+
def apply(*args)
|
11
|
+
curry.call(*args)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
class Method
|
16
|
+
#
|
17
|
+
# Returns a curried proc. If the optional arity argument is given,
|
18
|
+
# it determines the number of arguments. A curried proc receives
|
19
|
+
# some arguments. If a sufficient number of arguments are supplied,
|
20
|
+
# it passes the supplied arguments to the original proc and returns
|
21
|
+
# the result. Otherwise, returns another curried proc that takes the
|
22
|
+
# rest of arguments.
|
23
|
+
#
|
24
|
+
def curry(n=nil)
|
25
|
+
if n
|
26
|
+
to_proc.curry n
|
27
|
+
else
|
28
|
+
to_proc.curry
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
#
|
33
|
+
# Curries this Method and partially applies parameters.
|
34
|
+
# If a sufficient number of arguments are supplied, it passes the
|
35
|
+
# supplied arguments to the original proc and returns the result.
|
36
|
+
# Otherwise, returns another curried proc that takes the rest of
|
37
|
+
# arguments.
|
38
|
+
#
|
39
|
+
def apply(*args)
|
40
|
+
curry.call(*args)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
=begin
|
45
|
+
Copyright (c) 2014, Matthew Kerwin <matthew@kerwin.net.au>
|
46
|
+
|
47
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
48
|
+
purpose with or without fee is hereby granted, provided that the above
|
49
|
+
copyright notice and this permission notice appear in all copies.
|
50
|
+
|
51
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
52
|
+
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
53
|
+
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
54
|
+
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
55
|
+
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
56
|
+
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
57
|
+
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
58
|
+
=end
|
data/lib/mug/bool.rb
CHANGED
@@ -1,128 +1,128 @@
|
|
1
|
-
|
2
|
-
#
|
3
|
-
# Converts arg to a boolean (true or false).
|
4
|
-
#
|
5
|
-
def Bool(arg)
|
6
|
-
!!arg
|
7
|
-
end
|
8
|
-
|
9
|
-
class Object
|
10
|
-
#
|
11
|
-
# Converts obj to a boolean.
|
12
|
-
#
|
13
|
-
def to_bool
|
14
|
-
true
|
15
|
-
end
|
16
|
-
|
17
|
-
#
|
18
|
-
# Converts obj to a boolean.
|
19
|
-
#
|
20
|
-
def to_b
|
21
|
-
true
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
def nil.to_bool; false; end
|
26
|
-
def nil.to_b; false; end
|
27
|
-
def false.to_bool; false; end
|
28
|
-
def false.to_b; false; end
|
29
|
-
|
30
|
-
class Numeric
|
31
|
-
#
|
32
|
-
# Converts num to a boolean.
|
33
|
-
# Returns true if not zero.
|
34
|
-
#
|
35
|
-
def to_b
|
36
|
-
self != 0
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
class Float
|
41
|
-
#
|
42
|
-
# Converts num to a boolean.
|
43
|
-
# Returns true if not zero or NaN.
|
44
|
-
# Note: -0.0 is false, and +/-infinity are true.
|
45
|
-
#
|
46
|
-
def to_b
|
47
|
-
!(self.zero? || self.nan?)
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
class String
|
52
|
-
#
|
53
|
-
# Converts str to a boolean.
|
54
|
-
# Returns true if not empty.
|
55
|
-
#
|
56
|
-
def to_b
|
57
|
-
!empty?
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
class Array
|
62
|
-
#
|
63
|
-
# Converts ary to a boolean.
|
64
|
-
# Returns true if not empty.
|
65
|
-
#
|
66
|
-
def to_b
|
67
|
-
!empty?
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
|
-
class Hash
|
72
|
-
#
|
73
|
-
# Converts hsh to a boolean.
|
74
|
-
# Returns true if not empty.
|
75
|
-
#
|
76
|
-
def to_b
|
77
|
-
!empty?
|
78
|
-
end
|
79
|
-
end
|
80
|
-
|
81
|
-
module Enumerable
|
82
|
-
#
|
83
|
-
# Converts enum to a boolean.
|
84
|
-
# Returns true if there are any elements.
|
85
|
-
#
|
86
|
-
def to_b
|
87
|
-
any?{ true }
|
88
|
-
end
|
89
|
-
end
|
90
|
-
|
91
|
-
if RUBY_VERSION.to_i >= 2
|
92
|
-
class Enumerator
|
93
|
-
#
|
94
|
-
# Converts enum to a boolean.
|
95
|
-
# Returns true if there are any elements.
|
96
|
-
#
|
97
|
-
def to_b
|
98
|
-
size.to_b
|
99
|
-
end
|
100
|
-
end
|
101
|
-
end
|
102
|
-
|
103
|
-
class Exception
|
104
|
-
#
|
105
|
-
# Converts ex to a boolean.
|
106
|
-
# All Exceptions are considered false.
|
107
|
-
#
|
108
|
-
def to_b
|
109
|
-
false
|
110
|
-
end
|
111
|
-
end
|
112
|
-
|
113
|
-
=begin
|
114
|
-
Copyright (c) 2013, Matthew Kerwin <matthew@kerwin.net.au>
|
115
|
-
|
116
|
-
Permission to use, copy, modify, and/or distribute this software for any
|
117
|
-
purpose with or without fee is hereby granted, provided that the above
|
118
|
-
copyright notice and this permission notice appear in all copies.
|
119
|
-
|
120
|
-
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
121
|
-
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
122
|
-
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
123
|
-
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
124
|
-
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
125
|
-
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
126
|
-
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
127
|
-
=end
|
128
|
-
|
1
|
+
|
2
|
+
#
|
3
|
+
# Converts arg to a boolean (true or false).
|
4
|
+
#
|
5
|
+
def Bool(arg)
|
6
|
+
!!arg
|
7
|
+
end
|
8
|
+
|
9
|
+
class Object
|
10
|
+
#
|
11
|
+
# Converts obj to a boolean.
|
12
|
+
#
|
13
|
+
def to_bool
|
14
|
+
true
|
15
|
+
end
|
16
|
+
|
17
|
+
#
|
18
|
+
# Converts obj to a boolean.
|
19
|
+
#
|
20
|
+
def to_b
|
21
|
+
true
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def nil.to_bool; false; end
|
26
|
+
def nil.to_b; false; end
|
27
|
+
def false.to_bool; false; end
|
28
|
+
def false.to_b; false; end
|
29
|
+
|
30
|
+
class Numeric
|
31
|
+
#
|
32
|
+
# Converts num to a boolean.
|
33
|
+
# Returns true if not zero.
|
34
|
+
#
|
35
|
+
def to_b
|
36
|
+
self != 0
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
class Float
|
41
|
+
#
|
42
|
+
# Converts num to a boolean.
|
43
|
+
# Returns true if not zero or NaN.
|
44
|
+
# Note: -0.0 is false, and +/-infinity are true.
|
45
|
+
#
|
46
|
+
def to_b
|
47
|
+
!(self.zero? || self.nan?)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
class String
|
52
|
+
#
|
53
|
+
# Converts str to a boolean.
|
54
|
+
# Returns true if not empty.
|
55
|
+
#
|
56
|
+
def to_b
|
57
|
+
!empty?
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
class Array
|
62
|
+
#
|
63
|
+
# Converts ary to a boolean.
|
64
|
+
# Returns true if not empty.
|
65
|
+
#
|
66
|
+
def to_b
|
67
|
+
!empty?
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
class Hash
|
72
|
+
#
|
73
|
+
# Converts hsh to a boolean.
|
74
|
+
# Returns true if not empty.
|
75
|
+
#
|
76
|
+
def to_b
|
77
|
+
!empty?
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
module Enumerable
|
82
|
+
#
|
83
|
+
# Converts enum to a boolean.
|
84
|
+
# Returns true if there are any elements.
|
85
|
+
#
|
86
|
+
def to_b
|
87
|
+
any?{ true }
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
if RUBY_VERSION.to_i >= 2
|
92
|
+
class Enumerator
|
93
|
+
#
|
94
|
+
# Converts enum to a boolean.
|
95
|
+
# Returns true if there are any elements.
|
96
|
+
#
|
97
|
+
def to_b
|
98
|
+
size.to_b
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
class Exception
|
104
|
+
#
|
105
|
+
# Converts ex to a boolean.
|
106
|
+
# All Exceptions are considered false.
|
107
|
+
#
|
108
|
+
def to_b
|
109
|
+
false
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
=begin
|
114
|
+
Copyright (c) 2013, Matthew Kerwin <matthew@kerwin.net.au>
|
115
|
+
|
116
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
117
|
+
purpose with or without fee is hereby granted, provided that the above
|
118
|
+
copyright notice and this permission notice appear in all copies.
|
119
|
+
|
120
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
121
|
+
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
122
|
+
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
123
|
+
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
124
|
+
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
125
|
+
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
126
|
+
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
127
|
+
=end
|
128
|
+
|