quick-sampler 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/quick/sampler/dsl/fluidiom.rb +16 -1
- data/lib/quick/sampler/dsl/simple_combinators.rb +12 -2
- data/lib/quick/sampler/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 166249b4d99f3c75f161df7c7fcef6b0b544d407
|
4
|
+
data.tar.gz: efe98dc471d9e954c0159475dd2c13a8ea60c40a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1811619ab4d68251fd2f36ebf7bf23642288162dda1b2e24654e88141b69d543b72366ecd85134e8e93075873716a6547c794c7dfaa1dd8fc06a09df2cdfff17
|
7
|
+
data.tar.gz: 169017a885dc058a33b6cea98587c59824f6e97e9ed82c17ce121ad2a9f753bb5f47823a5a30649a9fb8ab8766dd25f957fd47bf7c62389af3dddc114952e18b
|
@@ -35,7 +35,7 @@ module Quick
|
|
35
35
|
# iterating when that many original values are tested.
|
36
36
|
#
|
37
37
|
# @return [Quick::Sampler]
|
38
|
-
# a sampler that
|
38
|
+
# a sampler that passes through only samples that satisfy the
|
39
39
|
# predicate given as block
|
40
40
|
# @yieldparam [Anything] sample
|
41
41
|
# a sampled value to be tested
|
@@ -44,6 +44,21 @@ module Quick
|
|
44
44
|
def such_that &predicate
|
45
45
|
spawn(unwrap.take(max_iterations).select(&predicate))
|
46
46
|
end
|
47
|
+
|
48
|
+
# spawn a mapping sampler
|
49
|
+
#
|
50
|
+
# The produced sampler will yield each original sample to the block and return block
|
51
|
+
# result instead.
|
52
|
+
#
|
53
|
+
# @return [Quick::Sampler]
|
54
|
+
# a sampler that maps each original sample through the block
|
55
|
+
# @yieldparam [Anything] sample
|
56
|
+
# the original sample
|
57
|
+
# @yieldreturn [Anything]
|
58
|
+
# the mapped sample to return
|
59
|
+
def map &block
|
60
|
+
spawn(unwrap.map(&block))
|
61
|
+
end
|
47
62
|
end
|
48
63
|
end
|
49
64
|
end
|
@@ -15,8 +15,8 @@ module Quick
|
|
15
15
|
case source
|
16
16
|
when Range
|
17
17
|
feed { rand(source) }
|
18
|
-
|
19
|
-
feed { source.sample }
|
18
|
+
else
|
19
|
+
feed { source.to_a.sample }
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
@@ -124,6 +124,16 @@ module Quick
|
|
124
124
|
}
|
125
125
|
end
|
126
126
|
|
127
|
+
# Arbitrary object sampler.
|
128
|
+
#
|
129
|
+
# @param [Class, Quick::Sampler<Class>] the_class
|
130
|
+
# a class of the object to create (or a sampler producing classes)
|
131
|
+
# @param [*Anything] *args
|
132
|
+
# arguments to pass to the constructor (may contain samplers)
|
133
|
+
def object_like the_class, *args
|
134
|
+
send_to(the_class, :new, *args)
|
135
|
+
end
|
136
|
+
|
127
137
|
private
|
128
138
|
|
129
139
|
def recursive_sample value
|