|
1098 | 1098 | res) |
1099 | 1099 |
|
1100 | 1100 | (defn mapcat |
1101 | | - ``Map a function over every element in an array or tuple and |
1102 | | - use `array/concat` to concatenate the results.`` |
| 1101 | + ``` |
| 1102 | + Map a function `f` over every value in a data structure `ind` |
| 1103 | + and use `array/concat` to concatenate the results, but only if |
| 1104 | + no `inds` are provided. Multiple data structures can be handled |
| 1105 | + if each `inds` is a data structure and `f` is a function of |
| 1106 | + arity one more than the number of `inds`. The resulting array |
| 1107 | + has a length that is the shortest of `ind` and each of `inds`. |
| 1108 | + ``` |
1103 | 1109 | [f ind & inds] |
1104 | 1110 | (def res @[]) |
1105 | 1111 | (map-template :mapcat res f ind inds) |
|
1116 | 1122 | res) |
1117 | 1123 |
|
1118 | 1124 | (defn count |
1119 | | - ``Count the number of items in `ind` for which `(pred item)` |
1120 | | - is true.`` |
| 1125 | + ``` |
| 1126 | + Count the number of values in a data structure `ind` for which |
| 1127 | + applying `pred` yields a truthy value, but only if no `inds` are |
| 1128 | + provided. Multiple data structures can be handled if each `inds` |
| 1129 | + is a data structure and `pred` is a function of arity one more |
| 1130 | + than the number of `inds`. Note that `pred` is only applied to |
| 1131 | + values at indeces up to the largest index of the shortest of |
| 1132 | + `ind` and each of `inds`. |
| 1133 | + ``` |
1121 | 1134 | [pred ind & inds] |
1122 | 1135 | (var res 0) |
1123 | 1136 | (map-template :count res pred ind inds) |
1124 | 1137 | res) |
1125 | 1138 |
|
1126 | 1139 | (defn keep |
1127 | | - ``Given a predicate `pred`, return a new array containing the truthy results |
1128 | | - of applying `pred` to each element in the indexed collection `ind`. This is |
1129 | | - different from `filter` which returns an array of the original elements where |
1130 | | - the predicate is truthy.`` |
| 1140 | + ``` |
| 1141 | + Given a predicate `pred`, return a new array containing the |
| 1142 | + truthy results of applying `pred` to each value in the data |
| 1143 | + structure `ind`, but only if no `inds` are provided. Multiple |
| 1144 | + data structures can be handled if each `inds` is a data |
| 1145 | + structure and `pred` is a function of arity one more than the |
| 1146 | + number of `inds`. The resulting array has a length that is the |
| 1147 | + shortest of `ind` and each of `inds`. |
| 1148 | + ``` |
1131 | 1149 | [pred ind & inds] |
1132 | 1150 | (def res @[]) |
1133 | 1151 | (map-template :keep res pred ind inds) |
|
2209 | 2227 | ret) |
2210 | 2228 |
|
2211 | 2229 | (defn all |
2212 | | - ``Returns true if `(pred item)` is truthy for every item in `ind`. |
2213 | | - Otherwise, returns the first falsey result encountered. |
2214 | | - Returns true if `ind` is empty.`` |
| 2230 | + ``` |
| 2231 | + Returns true if applying `pred` to every value in a data |
| 2232 | + structure `ind` results in only truthy values, but only if no |
| 2233 | + `inds` are provided. Multiple data structures can be handled |
| 2234 | + if each `inds` is a data structure and `pred` is a function |
| 2235 | + of arity one more than the number of `inds`. Returns the first |
| 2236 | + falsey result encountered. Note that `pred` is only called as |
| 2237 | + many times as the length of the shortest of `ind` and each of |
| 2238 | + `inds`. If `ind` or any of `inds` are empty, returns true. |
| 2239 | + ``` |
2215 | 2240 | [pred ind & inds] |
2216 | 2241 | (var res true) |
2217 | 2242 | (map-template :all res pred ind inds) |
2218 | 2243 | res) |
2219 | 2244 |
|
2220 | 2245 | (defn some |
2221 | | - ``Returns nil if `(pred item)` is false or nil for every item in `ind`. |
2222 | | - Otherwise, returns the first truthy result encountered.`` |
| 2246 | + ``` |
| 2247 | + Returns nil if applying `pred` to every value in a data |
| 2248 | + structure `ind` results in only falsey values, but only if no |
| 2249 | + `inds` are provided. Multiple data structures can be handled |
| 2250 | + if each `inds` is a data structure and `pred` is a function |
| 2251 | + of arity one more than the number of `inds`. Returns the first |
| 2252 | + truthy result encountered. Note that `pred` is conly called as |
| 2253 | + many times as the length of the shortest of `ind` and each of |
| 2254 | + `inds`. If `ind` or any of `inds` are empty, returns nil. |
| 2255 | + ``` |
2223 | 2256 | [pred ind & inds] |
2224 | 2257 | (var res nil) |
2225 | 2258 | (map-template :some res pred ind inds) |
|
0 commit comments