Skip to content

Commit 3db7299

Browse files
author
sogaiu
committed
Tweak doc for mapcat, count, keep, all, some
1 parent 363e32d commit 3db7299

File tree

1 file changed

+46
-13
lines changed

1 file changed

+46
-13
lines changed

src/boot/boot.janet

Lines changed: 46 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1098,8 +1098,14 @@
10981098
res)
10991099

11001100
(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+
```
11031109
[f ind & inds]
11041110
(def res @[])
11051111
(map-template :mapcat res f ind inds)
@@ -1116,18 +1122,30 @@
11161122
res)
11171123

11181124
(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+
```
11211134
[pred ind & inds]
11221135
(var res 0)
11231136
(map-template :count res pred ind inds)
11241137
res)
11251138

11261139
(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+
```
11311149
[pred ind & inds]
11321150
(def res @[])
11331151
(map-template :keep res pred ind inds)
@@ -2209,17 +2227,32 @@
22092227
ret)
22102228

22112229
(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+
```
22152240
[pred ind & inds]
22162241
(var res true)
22172242
(map-template :all res pred ind inds)
22182243
res)
22192244

22202245
(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+
```
22232256
[pred ind & inds]
22242257
(var res nil)
22252258
(map-template :some res pred ind inds)

0 commit comments

Comments
 (0)