functions 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -24,8 +24,58 @@ The lambda style is a bit more pure but is currently just a bit slower in perfor
24
24
 
25
25
  ### Lambda Style
26
26
 
27
+ The lambda style allows you to write functions like this
28
+
29
+ require 'functions'
30
+
31
+ module PreludeLambdaUsage
32
+
33
+ include Functions::Prelude
34
+
35
+ Power = ->(p,x) { x**p }.curry
36
+ Square = Power.(2)
37
+ Squares = Map.(Square)
38
+ Sum_Of_Squares2 = Sum < Squares
39
+
40
+ Average = After.( [Sum,Length] ).( Divide )
41
+
42
+ Gcd = ->(a,b) { (Divisors.(a) & Divisors.(b)).max }
43
+
44
+ # Gcd of an array
45
+ GcdA1 = Max < Intersect < Map.(Divisors) # litteral translation of the definition
46
+ GcdA2 = ReduceLeft.(Gcd) # faster
47
+
48
+ # Lcm of an array in function of Lcm of a pair
49
+ LcmA = ReduceLeft.(Lcm) # the same but without arguments
50
+
51
+ end
52
+
27
53
  ### Meta Style
28
54
 
55
+ The meta style allows you to write functions like this
56
+
57
+ require 'functions'
58
+
59
+ module PreludeMetaUsage
60
+
61
+ include Functions::PreludeMeta
62
+
63
+ def power(x, p) x ** p end
64
+
65
+ def square(x) power(x, 2) end
66
+
67
+ define :squares, as: { map: :square }
68
+
69
+ define :evens, as: { filter: :even? }
70
+
71
+ define :sum_of_squares_tris, as: { compose: [:sum, :squares] }
72
+
73
+ define :average, as: { :after => [ :sum_length, :divide ] }
74
+
75
+ define :sum, as: { foldl: [:add, 0]}
76
+
77
+ end
78
+
29
79
  ## Contributing
30
80
 
31
81
  1. Fork it
@@ -8,8 +8,8 @@ Gem::Specification.new do |gem|
8
8
  gem.version = Functions::VERSION
9
9
  gem.authors = ["Koen Handekyn"]
10
10
  gem.email = ["koen.handekyn@up-nxt.com"]
11
- gem.description = %q{functions programming in ruby}
12
- gem.summary = %q{functions programming in ruby}
11
+ gem.description = %q{functional programming in ruby}
12
+ gem.summary = %q{functional programming in ruby}
13
13
  gem.homepage = "https://github.com/koenhandekyn/functions"
14
14
 
15
15
  gem.files = `git ls-files`.split($/)
@@ -246,9 +246,7 @@ module Functions
246
246
  foldl(f(f), i, a.reverse)
247
247
  end
248
248
 
249
- def zip(a, b)
250
- a.zip(b)
251
- end
249
+ def zip(a, b) a.zip(b) end
252
250
 
253
251
  def map(a, f)
254
252
  a.map { |x| f(f).(x) }
@@ -1,3 +1,3 @@
1
1
  module Functions
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: functions
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -11,7 +11,7 @@ bindir: bin
11
11
  cert_chain: []
12
12
  date: 2013-04-10 00:00:00.000000000 Z
13
13
  dependencies: []
14
- description: functions programming in ruby
14
+ description: functional programming in ruby
15
15
  email:
16
16
  - koen.handekyn@up-nxt.com
17
17
  executables: []
@@ -67,7 +67,7 @@ rubyforge_project:
67
67
  rubygems_version: 1.8.24
68
68
  signing_key:
69
69
  specification_version: 3
70
- summary: functions programming in ruby
70
+ summary: functional programming in ruby
71
71
  test_files:
72
72
  - spec/prelude_lambda_math_spec.rb
73
73
  - spec/prelude_lambda_spec.rb