kansuu 0.0.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: cd9e82d8aeef5bd77a965b435623f4eb84bcfdf5
4
+ data.tar.gz: 155ed2774101cd8a7b57e824a4b3be172cb983b4
5
+ SHA512:
6
+ metadata.gz: 5d576bf6139b7dc4c3c791277cfe295f5d5a5fef3946735e6886f49d0be042048293fa477b35634ad24125a40a3da935ae6d275a039519e46bd2f8be1aee0e13
7
+ data.tar.gz: 25e6f7861c8cef56572e81c6147139a3dec6a957d616e3aaba0c0901138e59f5f11d96ebed9411773186c5eea4ffaa91a4d532741aa8e62a115d629c792390d3
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ /vendor
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.2.2
5
+ before_install: gem install bundler -v 1.12.5
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in kansuu.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,36 @@
1
+ # Kansuu
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/kansuu`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'kansuu'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install kansuu
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/kansuu.
36
+
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "kansuu"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/kansuu.gemspec ADDED
@@ -0,0 +1,33 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'kansuu/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "kansuu"
8
+ spec.version = Kansuu::VERSION
9
+ spec.authors = ["Akihito Fujiwara"]
10
+ spec.email = ["akitoha1207@gmail.com"]
11
+
12
+ spec.summary = %q{Functions (Procedures)}
13
+ spec.description = %q{Functions (Procedures)}
14
+ spec.homepage = "https://github.com/akihitofujiwara/kansuu.git"
15
+
16
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
17
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
18
+ # if spec.respond_to?(:metadata)
19
+ # spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
20
+ # else
21
+ # raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
22
+ # end
23
+
24
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
25
+ spec.bindir = "exe"
26
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
27
+ spec.require_paths = ["lib"]
28
+
29
+ spec.add_development_dependency "bundler", "~> 1.12"
30
+ spec.add_development_dependency "rake", "~> 10.0"
31
+ spec.add_development_dependency "rspec", "~> 3.0"
32
+ spec.add_dependency "lambda_driver", "~> 1.2.4"
33
+ end
@@ -0,0 +1,21 @@
1
+ require "lambda_driver"
2
+ require "kansuu/util"
3
+
4
+ module Kansuu::Cast
5
+ extend Kansuu::Util
6
+
7
+ __define_funcs_from_method < {
8
+ to_str: [:to_s, 1],
9
+ to_sym: [:to_sym, 1],
10
+ to_a: [:to_a, 1],
11
+ to_arr: [:to_arr, 1],
12
+ to_i: [:to_i, 1],
13
+ to_int: [:to_int, 1],
14
+ to_c: [:to_c, 1],
15
+ to_r: [:to_r, 1],
16
+ to_f: [:to_f, 1],
17
+ to_enum: [:to_enum, 1],
18
+ to_h: [:to_h, 1],
19
+ }
20
+ end
21
+
@@ -0,0 +1,23 @@
1
+ require "lambda_driver"
2
+ require "kansuu/util"
3
+
4
+ module Kansuu::Combinator
5
+ extend Kansuu::Util
6
+
7
+ __define_func_from_method.(:flip, :flip, 2)
8
+
9
+ def id
10
+ -> x { x }
11
+ end
12
+
13
+ def const
14
+ -> x, y { x } % 2
15
+ end
16
+
17
+ def i; id end
18
+
19
+ def k; const end
20
+
21
+ def c; flip end
22
+ end
23
+
@@ -0,0 +1,15 @@
1
+ require "lambda_driver"
2
+
3
+ module Kansuu::Control
4
+ def when_
5
+ -> f, g, x {
6
+ f[x] ? g[x] : x
7
+ } % 3
8
+ end
9
+
10
+ def except
11
+ -> f, g, x {
12
+ f[x] ? x : g[x]
13
+ } % 3
14
+ end
15
+ end
@@ -0,0 +1,107 @@
1
+ require "lambda_driver"
2
+ require "kansuu/util"
3
+ require "kansuu/func"
4
+
5
+ module Kansuu::Enum
6
+ extend Kansuu::Util
7
+
8
+ __define_funcs_from_method < {
9
+ sort: [:sort, 1],
10
+ sort_by: [:sort_by, 2, true],
11
+ grep: [:grep, 2],
12
+ count: [:count, 1],
13
+ find: [:find, 2, true],
14
+ detect: [:detect, 2, true],
15
+ find_index: [:find_index, 2, true],
16
+ find_all: [:find_all, 2, true],
17
+ select: [:select, 2, true],
18
+ filter: [:select, 2, true],
19
+ reject: [:reject, 2, true],
20
+ collect: [:collect, 2, true],
21
+ map: [:map, 2, true],
22
+ flat_map: [:flat_map, 2, true],
23
+ collect_concat: [:collect_concat, 2, true],
24
+ inject: [:inject, 3, true],
25
+ reduce: [:reduce, 3, true],
26
+ fold: [:reduce, 3, true],
27
+ foldl: [:reduce, 3, true],
28
+ fold1: [:reduce, 2, true],
29
+ foldl1: [:reduce, 2, true],
30
+ partition: [:partition, 2, true],
31
+ group_by: [:group_by, 2, true],
32
+ first: [:first, 1],
33
+ all: [:all?, 2, true],
34
+ any: [:any?, 2, true],
35
+ one: [:one?, 2, true],
36
+ none: [:none?, 2, true],
37
+ min: [:min, 1],
38
+ max: [:max, 1],
39
+ minmax: [:minmax, 1],
40
+ min_by: [:min_by, 2, true],
41
+ max_by: [:max_by, 2, true],
42
+ minmax_by: [:minmax_by, 2, true],
43
+ is_member: [:member?, 2],
44
+ include_: [:include?, 2],
45
+ each_with_index: [:each_with_index, 2, true],
46
+ reverse_each: [:reverse_each, 2, true],
47
+ each_entry: [:each_entry, 2, true],
48
+ each_slice: [:each_slice, 3, true],
49
+ each_cons: [:each_cons, 3, true],
50
+ each_with_object: [:each_with_object, 3, true],
51
+ zipr: [:zip, 2],
52
+ take: [:take, 2],
53
+ take_while: [:take_while, 2, true],
54
+ drop: [:drop, 2],
55
+ drop_while: [:drop_while, 2, true],
56
+ cycle: [:cycle, 3, true],
57
+ chunk: [:chunk, 2, true],
58
+ slice_before: [:slice_before, 2, true],
59
+ slice_after: [:slice_after, 2, true],
60
+ slice_when: [:slice_when, 2, true],
61
+ lazy: [:lazy, 1],
62
+ force: [:force, 1],
63
+ at: [:at, 2],
64
+ last: [:last, 1],
65
+ concat: [:concat, 2],
66
+ each: [:each, 2, true],
67
+ each_index: [:each_index, 2, true],
68
+ length: [:length, 1],
69
+ size: [:size, 1],
70
+ empty: [:empty?, 1],
71
+ index: [:index, 2],
72
+ rindex: [:rindex, 2],
73
+ join: [:join, 2],
74
+ reverse: [:reverse, 1],
75
+ rotate: [:rotate, 2],
76
+ slice: [:slice, 3],
77
+ uniq: [:uniq, 1],
78
+ unique: [:uniq, 1],
79
+ compact: [:compact, 1],
80
+ flatten: [:flatten, 1],
81
+ shuffle: [:shuffle, 1],
82
+ sample: [:sample, 1],
83
+ samples: [:sample, 2],
84
+ permutation: [:permutation, 2],
85
+ combination: [:combination, 2],
86
+ repeated_permutation: [:repeated_permutation, 2],
87
+ repeated_combination: [:repeated_combination, 2],
88
+ product: [:product, 2],
89
+ }
90
+
91
+ def zipl; zipr.flip 2 end
92
+
93
+ def zip; zipl end
94
+
95
+ def zip_with
96
+ -> f, xs, ys {
97
+ xs.zip(ys).map &app[f]
98
+ } % 3
99
+ end
100
+
101
+ def pick
102
+ -> ns, xs {
103
+ xs.values_at *ns
104
+ }
105
+ end
106
+ end
107
+
data/lib/kansuu/eq.rb ADDED
@@ -0,0 +1,15 @@
1
+ require "lambda_driver"
2
+ require "kansuu/util"
3
+
4
+ module Kansuu::Eq
5
+ extend Kansuu::Util
6
+
7
+ __define_funcs_from_method < {
8
+ is: [:===, 2],
9
+ eq: [:===, 2],
10
+ equals: [:===, 2],
11
+ isnt: [:!=, 2],
12
+ not_eq: [:!=, 2],
13
+ not_equals: [:!=, 2],
14
+ }
15
+ end
@@ -0,0 +1,82 @@
1
+ require "lambda_driver"
2
+
3
+ module Kansuu::Func
4
+ def ap
5
+ -> f, x { f[x] } % 2
6
+ end
7
+
8
+ def app
9
+ -> f, xs { f[*xs] } % 2
10
+ end
11
+
12
+ def ap_all
13
+ -> fs, x { fs.map &(ap * x) } % 2
14
+ end
15
+
16
+ def ap_at
17
+ -> n, f, xs {
18
+ xs[0...n] + [(f[xs[n]])] + xs[(n+1)...xs.length]
19
+ } % 3
20
+ end
21
+
22
+ def ap_zip
23
+ -> fs, ys {
24
+ fs.zip(ys).map &app[ap]
25
+ } % 2
26
+ end
27
+
28
+ def ap_head
29
+ ap_at[0]
30
+ end
31
+
32
+ def ap_last
33
+ -> f, xs {
34
+ ap_at[xs.length - 1, f, xs]
35
+ }
36
+ end
37
+
38
+ def dest
39
+ ap_all.flip % 2
40
+ end
41
+
42
+ def withl
43
+ -> f, x {
44
+ [f[x], x]
45
+ } % 2
46
+ end
47
+
48
+ def withr
49
+ -> f, x {
50
+ [x, f[x]]
51
+ } % 2
52
+ end
53
+
54
+ def args
55
+ -> *xs { xs }
56
+ end
57
+
58
+ def arg
59
+ -> n, *xs { xs[n] } % 2
60
+ end
61
+
62
+ def ap_arg
63
+ -> n, f, g {
64
+ args >> ap_at[n, f] >> app[g]
65
+ } % 3
66
+ end
67
+
68
+ def ap_find
69
+ -> f, g, xs {
70
+ ap_at[find_index[f, xs], g, xs]
71
+ } % 3
72
+ end
73
+
74
+ def ap_select
75
+ -> f, g, xs {
76
+ xs.map &-> x {
77
+ f[x] ? g[x] : x
78
+ }
79
+ } % 3
80
+ end
81
+ end
82
+
data/lib/kansuu/num.rb ADDED
@@ -0,0 +1,49 @@
1
+ require "lambda_driver"
2
+ require "kansuu/util"
3
+
4
+ module Kansuu::Num
5
+ extend Kansuu::Util
6
+
7
+ __define_funcs_from_method < {
8
+ plus: [:+, 2],
9
+ minus: [:-, 2],
10
+ subtract: [:-, 2],
11
+ sub: [:-, 2],
12
+ multiply: [:*, 2],
13
+ mul: [:*, 2],
14
+ pow: [:**, 2],
15
+ div: [:div, 2],
16
+ modulo: [:modulo, 2],
17
+ remainder: [:remainder, 2],
18
+ rem: [:remainder, 2],
19
+ divmod: [:divmod, 2],
20
+ fdiv: [:fdiv, 2],
21
+ abs: [:abs, 1],
22
+ magnitude: [:magnitude, 1],
23
+ bit_length: [:bit_length, 1],
24
+ odd: [:odd?, 1],
25
+ even: [:even?, 1],
26
+ succ: [:succ, 1],
27
+ upto: [:upto, 2],
28
+ downto: [:downto, 2],
29
+ repeat: [:times, 2, true],
30
+ next: [:next, 1],
31
+ pred: [:pred, 1],
32
+ chr: [:chr, 1],
33
+ ord: [:ord, 1],
34
+ floor: [:floor, 1],
35
+ ceil: [:ceil, 1],
36
+ truncate: [:truncate, 1],
37
+ round: [:round, 1],
38
+ gcd: [:gcd, 2],
39
+ lcm: [:lcm, 2],
40
+ gcdlcm: [:gcdlcm, 2],
41
+ rationalize: [:rationalize, 1],
42
+ quo: [:quo, 2],
43
+ abs2: [:abs2, 1],
44
+ between: [:between?, 3],
45
+ }
46
+ end
47
+
48
+
49
+
data/lib/kansuu/obj.rb ADDED
@@ -0,0 +1,34 @@
1
+ require "lambda_driver"
2
+
3
+ module Kansuu::Obj
4
+ def let
5
+ -> o, m, *args {
6
+ o._(m)[*args]
7
+ } % 3
8
+ end
9
+
10
+ def disp
11
+ -> m, *args, o {
12
+ o._(m)[*args]
13
+ } % 3
14
+ end
15
+
16
+ def get
17
+ -> k, o {
18
+ o.send(k)
19
+ } % 2
20
+ end
21
+
22
+ def set
23
+ -> k, v, o {
24
+ o.send("#{k}=", v)
25
+ } % 3
26
+ end
27
+
28
+ def set_ap
29
+ -> k, f, o {
30
+ set[k, f[get[k, o]], o]
31
+ } % 3
32
+ end
33
+ end
34
+
data/lib/kansuu/ord.rb ADDED
@@ -0,0 +1,13 @@
1
+ require "lambda_driver"
2
+ require "kansuu/util"
3
+
4
+ module Kansuu::Ord
5
+ extend Kansuu::Util
6
+
7
+ __define_funcs_from_method < {
8
+ lt: [:<, 2],
9
+ lte: [:<=, 2],
10
+ gt: [:>, 2],
11
+ gte: [:>=, 2],
12
+ }
13
+ end
@@ -0,0 +1,17 @@
1
+ require "lambda_driver"
2
+
3
+ module Kansuu::Util
4
+ def __define_func_from_method
5
+ -> name, method, arity, with_proc = false {
6
+ define_method name, (
7
+ with_proc ?
8
+ -> *a, p, o { o._(method).(*a, &p) } % arity
9
+ : -> *a, o { o._(method).(*a) } % arity
10
+ )
11
+ }
12
+ end
13
+
14
+ def __define_funcs_from_method
15
+ -> hash { hash.each &-> k, v { __define_func_from_method.(k, *v) } }
16
+ end
17
+ end
@@ -0,0 +1,3 @@
1
+ module Kansuu
2
+ VERSION = "0.0.0"
3
+ end
data/lib/kansuu.rb ADDED
@@ -0,0 +1,24 @@
1
+ require "lambda_driver"
2
+ require "kansuu/version"
3
+ require "kansuu/cast"
4
+ require "kansuu/combinator"
5
+ require "kansuu/control"
6
+ require "kansuu/enum"
7
+ require "kansuu/eq"
8
+ require "kansuu/func"
9
+ require "kansuu/num"
10
+ require "kansuu/obj"
11
+ require "kansuu/ord"
12
+
13
+ module Kansuu
14
+ include Kansuu::Cast
15
+ include Kansuu::Combinator
16
+ include Kansuu::Control
17
+ include Kansuu::Enum
18
+ include Kansuu::Eq
19
+ include Kansuu::Func
20
+ include Kansuu::Num
21
+ include Kansuu::Obj
22
+ include Kansuu::Ord
23
+ end
24
+
metadata ADDED
@@ -0,0 +1,120 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: kansuu
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Akihito Fujiwara
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-07-06 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.12'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.12'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: lambda_driver
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 1.2.4
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 1.2.4
69
+ description: Functions (Procedures)
70
+ email:
71
+ - akitoha1207@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - ".rspec"
78
+ - ".travis.yml"
79
+ - Gemfile
80
+ - README.md
81
+ - Rakefile
82
+ - bin/console
83
+ - bin/setup
84
+ - kansuu.gemspec
85
+ - lib/kansuu.rb
86
+ - lib/kansuu/cast.rb
87
+ - lib/kansuu/combinator.rb
88
+ - lib/kansuu/control.rb
89
+ - lib/kansuu/enum.rb
90
+ - lib/kansuu/eq.rb
91
+ - lib/kansuu/func.rb
92
+ - lib/kansuu/num.rb
93
+ - lib/kansuu/obj.rb
94
+ - lib/kansuu/ord.rb
95
+ - lib/kansuu/util.rb
96
+ - lib/kansuu/version.rb
97
+ homepage: https://github.com/akihitofujiwara/kansuu.git
98
+ licenses: []
99
+ metadata: {}
100
+ post_install_message:
101
+ rdoc_options: []
102
+ require_paths:
103
+ - lib
104
+ required_ruby_version: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - ">="
107
+ - !ruby/object:Gem::Version
108
+ version: '0'
109
+ required_rubygems_version: !ruby/object:Gem::Requirement
110
+ requirements:
111
+ - - ">="
112
+ - !ruby/object:Gem::Version
113
+ version: '0'
114
+ requirements: []
115
+ rubyforge_project:
116
+ rubygems_version: 2.4.5
117
+ signing_key:
118
+ specification_version: 4
119
+ summary: Functions (Procedures)
120
+ test_files: []