arrays 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSE +20 -0
- data/README.md +7 -0
- data/{RakeFile → Rakefile} +0 -0
- data/arrays-0.0.1.gem +0 -0
- data/arrays.gemspec +2 -2
- data/lib/arrays.rb +4 -5
- metadata +6 -6
- data/lib/arrays.rb~ +0 -65
- data/test/test_arrays.rb~ +0 -19
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a5e0ae984f014f87dc5e93ed33af879ede7fb1ba
|
4
|
+
data.tar.gz: 582b119d5c552c6460df6953a7bee43aad965ea6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7f774448509e2c985c706fb2a7c4b967963a320bb6eb8930bdb887135e057cec8a475161b1f40c3f35c411f9337ac7b06ac71bab0aab72c22838764b9875a45d
|
7
|
+
data.tar.gz: b41239bc540249d106b01f333283a1948107d26f6a9149c5478c4aa1ef640a67f7cf24d4b38adcfdc7a6709628db02cb384133d05e1922ee003243e24cada362
|
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2013 daewon
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
6
|
+
this software and associated documentation files (the "Software"), to deal in
|
7
|
+
the Software without restriction, including without limitation the rights to
|
8
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
9
|
+
the Software, and to permit persons to whom the Software is furnished to do so,
|
10
|
+
subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
17
|
+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
18
|
+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
19
|
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
20
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
data/{RakeFile → Rakefile}
RENAMED
File without changes
|
data/arrays-0.0.1.gem
CHANGED
Binary file
|
data/arrays.gemspec
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = 'arrays'
|
3
|
-
s.version = '0.0.
|
4
|
-
s.date = '2013-07-
|
3
|
+
s.version = '0.0.2'
|
4
|
+
s.date = '2013-07-24'
|
5
5
|
s.summary = "useful method for array like list"
|
6
6
|
s.description = "array extensions for functional programming"
|
7
7
|
s.authors = ["daewon"]
|
data/lib/arrays.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
# Array extension
|
2
|
+
|
2
3
|
class Array
|
3
4
|
|
4
5
|
# cluster element with keep order
|
@@ -6,7 +7,7 @@ class Array
|
|
6
7
|
# [1, 2, 2, 2].cluster { |a, b| a == b }
|
7
8
|
# => [[1], [2, 2, 2]]
|
8
9
|
def cluster &block
|
9
|
-
self.inject([])
|
10
|
+
self.inject([]) do |acc, item|
|
10
11
|
if acc.empty?
|
11
12
|
[[item]]
|
12
13
|
else
|
@@ -17,7 +18,7 @@ class Array
|
|
17
18
|
end
|
18
19
|
acc
|
19
20
|
end
|
20
|
-
|
21
|
+
end
|
21
22
|
end
|
22
23
|
|
23
24
|
# throw exception if list is empty
|
@@ -44,8 +45,6 @@ class Array
|
|
44
45
|
# take one element
|
45
46
|
# [1, 2].head
|
46
47
|
# => 1
|
47
|
-
|
48
|
-
self.first
|
49
|
-
end
|
48
|
+
alias head first
|
50
49
|
end
|
51
50
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: arrays
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- daewon
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-07-
|
11
|
+
date: 2013-07-24 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: array extensions for functional programming
|
14
14
|
email: blueiur@gmail.com
|
@@ -18,11 +18,11 @@ extra_rdoc_files: []
|
|
18
18
|
files:
|
19
19
|
- arrays-0.0.1.gem
|
20
20
|
- arrays.gemspec
|
21
|
+
- LICENSE
|
22
|
+
- README.md
|
21
23
|
- lib/arrays.rb
|
22
|
-
-
|
23
|
-
- RakeFile
|
24
|
+
- Rakefile
|
24
25
|
- test/test_arrays.rb
|
25
|
-
- test/test_arrays.rb~
|
26
26
|
homepage: http://daewon.github.com
|
27
27
|
licenses: []
|
28
28
|
metadata: {}
|
@@ -42,7 +42,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
42
42
|
version: '0'
|
43
43
|
requirements: []
|
44
44
|
rubyforge_project:
|
45
|
-
rubygems_version: 2.0.
|
45
|
+
rubygems_version: 2.0.3
|
46
46
|
signing_key:
|
47
47
|
specification_version: 4
|
48
48
|
summary: useful method for array like list
|
data/lib/arrays.rb~
DELETED
@@ -1,65 +0,0 @@
|
|
1
|
-
#!`which ruby`
|
2
|
-
|
3
|
-
# Array extension
|
4
|
-
class Array
|
5
|
-
# cluster element with keep order
|
6
|
-
# accept binary predicate function
|
7
|
-
# [1, 2, 2, 2].cluster { |a, b| a == b }
|
8
|
-
# => [[1], [2, 2, 2]]
|
9
|
-
def cluster &block
|
10
|
-
self.inject([]) { |acc, item|
|
11
|
-
if acc.empty?
|
12
|
-
[[item]]
|
13
|
-
else
|
14
|
-
if block.call(acc[-1][-1], item)
|
15
|
-
acc[-1] << item
|
16
|
-
else
|
17
|
-
acc << [item]
|
18
|
-
end
|
19
|
-
acc
|
20
|
-
end
|
21
|
-
}
|
22
|
-
end
|
23
|
-
|
24
|
-
# throw exception if list is empty
|
25
|
-
def check_empty_list
|
26
|
-
throw ":empty list" if self.empty?
|
27
|
-
end
|
28
|
-
|
29
|
-
# drop last one element
|
30
|
-
# [1, 2].tail
|
31
|
-
# => [2]
|
32
|
-
def init
|
33
|
-
check_empty_list
|
34
|
-
self.take(self.length-1)
|
35
|
-
end
|
36
|
-
|
37
|
-
# drop one element
|
38
|
-
# [1, 2].tail
|
39
|
-
# => [2]
|
40
|
-
def tail
|
41
|
-
check_empty_list
|
42
|
-
self.drop(1)
|
43
|
-
end
|
44
|
-
|
45
|
-
# take one element
|
46
|
-
# [1, 2].head
|
47
|
-
# => 1
|
48
|
-
def head
|
49
|
-
self.first
|
50
|
-
end
|
51
|
-
|
52
|
-
end
|
53
|
-
|
54
|
-
# test
|
55
|
-
cluster = [1, 2, 3, 3, 3, 5, 5, 6].cluster {|a, b| a == b }
|
56
|
-
p cluster.inspect
|
57
|
-
|
58
|
-
init = [1, 2].init
|
59
|
-
p init.inspect
|
60
|
-
|
61
|
-
tail = [1, 2].tail
|
62
|
-
p tail.inspect
|
63
|
-
|
64
|
-
head = [1, 2].head
|
65
|
-
p head.inspect
|
data/test/test_arrays.rb~
DELETED
@@ -1,19 +0,0 @@
|
|
1
|
-
require 'test/unit'
|
2
|
-
require 'hola'
|
3
|
-
|
4
|
-
class HolaTest < Test::Unit::TestCase
|
5
|
-
def test_english_hello
|
6
|
-
assert_equal "hello world",
|
7
|
-
Hola.hi("english")
|
8
|
-
end
|
9
|
-
|
10
|
-
def test_any_hello
|
11
|
-
assert_equal "hello world",
|
12
|
-
Hola.hi("ruby")
|
13
|
-
end
|
14
|
-
|
15
|
-
def test_spanish_hello
|
16
|
-
assert_equal "hola mundo",
|
17
|
-
Hola.hi("spanish")
|
18
|
-
end
|
19
|
-
end
|