http_fn 0.1.1 → 0.1.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 194bd7ff500a4dfbe818e70197ab5db7728ff7c243a31d92392c7912d10371eb
4
- data.tar.gz: 844b65792a38d7c008a6a81462e92f580b6daa60a0e446dd011088b7e1afff4e
3
+ metadata.gz: 04320754f24479e425e4e8517bd34414e1174be0346d96a4e12cbb5f8508e97d
4
+ data.tar.gz: d15ef868864f0bf47f16057bcb5bfe5be0f843949a492fcfe8606ff1c26243b3
5
5
  SHA512:
6
- metadata.gz: ac8ff07d43e82facf96ea66ca8fb3534fdbe5fef4d15a8abd6eb0ca13d40ebfa848ef0e91398d1de0ec621d5c9bee982b5a7c16e16ddadba1de80756714ed174
7
- data.tar.gz: dfc8bc0157f372b1339b27315924e49e4f929dd2dc19fb6274be3475e40e14c47e31cfde8f9118a949355c436a4dccca0add6e4627d4fce41b7e87307385681f
6
+ metadata.gz: e483e80dea589e759fcdbe8525ef5eb4a87e951e337410e24af5f3db98b90cedbd19924df584dcd1ee3ed6eb5c3327cbf217fa1fe97f32760d82f8075ffd35b2
7
+ data.tar.gz: 852ce1cbd0cdd7090da788e70603282d172639925d75acf0673ff6ccd8f9e7d435af7115ec42638dba785c12e2d6774552370c2912b83a5f53355a8f83f002fb
data/lib/http_fn/utils.rb CHANGED
@@ -2,61 +2,63 @@ require "json"
2
2
  require "pp"
3
3
  require "yaml"
4
4
 
5
- module Utils
6
- fn_reader :parse_json, :debug, :at, :retry_fn,
7
- :record, :player, :count_by, :cache, :red, :time,
8
- :expired, :apply, :and_then, :default, :map, :get, :try
5
+ module HttpFn
6
+ module Utils
7
+ fn_reader :parse_json, :debug, :at, :retry_fn,
8
+ :record, :player, :count_by, :cache, :red, :time,
9
+ :expired, :apply, :and_then, :default, :map, :get, :try
9
10
 
10
- @@parse_json = JSON.method(:parse)
11
- @@debug = ->print, a, b { print.(a); print.(b.to_s); b }.curry
12
- @@at = ->key, hash { hash[key] }.curry
13
- @@red = ->a { "\033[31m#{a}\033[0m" }
14
- # ( a -> b ) -> a -> b
15
- @@try = ->f, a { a.nil? ? nil : f.(a) }.curry
16
- @@retry_fn = ->fn, a {
17
- begin
18
- fn.(a)
19
- rescue
20
- sleep(1)
21
- puts "RETRYING"
22
- @@retry_fn.(fn).(a)
23
- end
24
- }.curry
25
- @@record = ->filename, to_save {
26
- File.open(filename, "w+") { |a| a << to_save.to_yaml }
27
- to_save
28
- }.curry
29
- @@play = ->filename, _params { YAML.load(File.read(filename)) }.curry
30
- # (Float -> String -> Bool) -> String -> (a -> b) -> b
31
- @@cache = ->expired, filename, fn, param {
32
- if expired.(filename)
33
- @@record.(filename).(fn.(param))
34
- else
35
- puts "reading from cache"
36
- @@play.(filename).(nil)
37
- end
38
- }.curry
39
- @@expired = ->sec, a { !File.exist?(a) || (Time.now - File.mtime(a)) > sec }.curry
40
- @@count_by = ->fn, a {
41
- a.inject({}) do |res, a|
42
- by = fn.(a)
43
- res[by] ||= 0
44
- res[by] += 1
45
- res
46
- end
47
- }.curry
11
+ @@parse_json = JSON.method(:parse)
12
+ @@debug = ->print, a, b { print.(a); print.(b.to_s); b }.curry
13
+ @@at = ->key, hash { hash[key] }.curry
14
+ @@red = ->a { "\033[31m#{a}\033[0m" }
15
+ # ( a -> b ) -> a -> b
16
+ @@try = ->f, a { a.nil? ? nil : f.(a) }.curry
17
+ @@retry_fn = ->fn, a {
18
+ begin
19
+ fn.(a)
20
+ rescue
21
+ sleep(1)
22
+ puts "RETRYING"
23
+ @@retry_fn.(fn).(a)
24
+ end
25
+ }.curry
26
+ @@record = ->filename, to_save {
27
+ File.open(filename, "w+") { |a| a << to_save.to_yaml }
28
+ to_save
29
+ }.curry
30
+ @@play = ->filename, _params { YAML.load(File.read(filename)) }.curry
31
+ # (Float -> String -> Bool) -> String -> (a -> b) -> b
32
+ @@cache = ->expired, filename, fn, param {
33
+ if expired.(filename)
34
+ @@record.(filename).(fn.(param))
35
+ else
36
+ puts "reading from cache"
37
+ @@play.(filename).(nil)
38
+ end
39
+ }.curry
40
+ @@expired = ->sec, a { !File.exist?(a) || (Time.now - File.mtime(a)) > sec }.curry
41
+ @@count_by = ->fn, a {
42
+ a.inject({}) do |res, a|
43
+ by = fn.(a)
44
+ res[by] ||= 0
45
+ res[by] += 1
46
+ res
47
+ end
48
+ }.curry
48
49
 
49
- # (String -> String) -> String -> ( a -> b ) -> a -> b
50
- @@time = ->print, msg, fn, a {
51
- start_time = Time.now
52
- res = fn.(a)
53
- print.("Time duration for #{msg} = #{Time.now - start_time}")
54
- res
55
- }.curry
56
- @@apply = ->method, a { a.send(method) }.curry
57
- @@default = ->default, a { a.nil? ? default : a }.curry
58
- @@and_then = ->f, a { a.nil? ? nil : f.(a) }.curry
59
- @@map = ->f, enum { enum.map(&f) }.curry
60
- @@at = ->key, hash { hash; hash[key] }.curry
61
- @@get = ->method, obj { obj.send(method) }.curry
50
+ # (String -> String) -> String -> ( a -> b ) -> a -> b
51
+ @@time = ->print, msg, fn, a {
52
+ start_time = Time.now
53
+ res = fn.(a)
54
+ print.("Time duration for #{msg} = #{Time.now - start_time}")
55
+ res
56
+ }.curry
57
+ @@apply = ->method, a { a.send(method) }.curry
58
+ @@default = ->default, a { a.nil? ? default : a }.curry
59
+ @@and_then = ->f, a { a.nil? ? nil : f.(a) }.curry
60
+ @@map = ->f, enum { enum.map(&f) }.curry
61
+ @@at = ->key, hash { hash; hash[key] }.curry
62
+ @@get = ->method, obj { obj.send(method) }.curry
63
+ end
62
64
  end
@@ -1,3 +1,3 @@
1
1
  module HttpFn
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: http_fn
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Martin Chabot