Skip to content

Commit 34adc4d

Browse files
doc: add missing docstrings (#11364)
This PR adds missing docstrings for constants that occur in the reference manual. --------- Co-authored-by: Johannes Tantow <[email protected]>
1 parent 5fb25ff commit 34adc4d

File tree

7 files changed

+129
-4
lines changed

7 files changed

+129
-4
lines changed

src/Init/Data/ByteArray/Basic.lean

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,11 @@ Copies the bytes with indices {name}`b` (inclusive) to {name}`e` (exclusive) to
132132
def extract (a : ByteArray) (b e : Nat) : ByteArray :=
133133
a.copySlice b empty 0 (e - b)
134134

135+
/--
136+
Appends two byte arrays using fast array primitives instead of converting them into lists and back.
137+
138+
In compiled code, this function replaces calls to {name}`ByteArray.append`.
139+
-/
135140
@[inline]
136141
protected def fastAppend (a : ByteArray) (b : ByteArray) : ByteArray :=
137142
-- we assume that `append`s may be repeated, so use asymptotic growing; use `copySlice` directly to customize

src/Init/Data/Iterators/Basic.lean

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -678,6 +678,7 @@ Given this typeclass, termination proofs for well-founded recursion over an iter
678678
`it.finitelyManySteps` as a termination measure.
679679
-/
680680
class Finite (α : Type w) (m : Type w → Type w') {β : Type w} [Iterator α m β] : Prop where
681+
/-- The relation of plausible successors is well-founded. -/
681682
wf : WellFounded (IterM.IsPlausibleSuccessorOf (α := α) (m := m))
682683

683684
theorem Finite.wf_of_id {α : Type w} {β : Type w} [Iterator α Id β] [Finite α Id] :
@@ -797,6 +798,7 @@ Given this typeclass, termination proofs for well-founded recursion over an iter
797798
`it.finitelyManySkips` as a termination measure.
798799
-/
799800
class Productive (α m) {β} [Iterator α m β] : Prop where
801+
/-- The relation of plausible successors during skips is well-founded. -/
800802
wf : WellFounded (IterM.IsPlausibleSkipSuccessorOf (α := α) (m := m))
801803

802804
/--

src/Init/Data/Iterators/Consumers/Loop.lean

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ prelude
99
public import Init.Data.Iterators.Consumers.Collect
1010
public import Init.Data.Iterators.Consumers.Monadic.Loop
1111

12+
set_option linter.missingDocs true
13+
1214
public section
1315

1416
/-!
@@ -46,6 +48,9 @@ instance (α : Type w) (β : Type w) (n : Type x → Type x') [Monad n]
4648
haveI : ForIn' n (Iter (α := α) β) β _ := Iter.instForIn'
4749
instForInOfForIn'
4850

51+
/--
52+
An implementation of `for h : ... in ... do ...` notation for partial iterators.
53+
-/
4954
@[always_inline, inline]
5055
def Iter.Partial.instForIn' {α : Type w} {β : Type w} {n : Type x → Type x'} [Monad n]
5156
[Iterator α Id β] [IteratorLoopPartial α Id n] :
@@ -202,6 +207,11 @@ def Iter.all {α β : Type w}
202207
(p : β → Bool) (it : Iter (α := α) β) : Bool :=
203208
(it.allM (fun x => pure (f := Id) (p x))).run
204209

210+
/--
211+
Steps through the iterator until the monadic function `f` returns `some` for an element, at which
212+
point iteration stops and the result of `f` is returned. If the iterator is completely consumed
213+
without `f` returning `some`, then the result is `none`.
214+
-/
205215
@[inline]
206216
def Iter.findSomeM? {α β : Type w} {γ : Type x} {m : Type x → Type w'} [Monad m] [Iterator α Id β]
207217
[IteratorLoop α Id m] [Finite α Id] (it : Iter (α := α) β) (f : β → m (Option γ)) :
@@ -211,7 +221,7 @@ def Iter.findSomeM? {α β : Type w} {γ : Type x} {m : Type x → Type w'} [Mon
211221
| none => return .yield none
212222
| some fx => return .done (some fx))
213223

214-
@[inline]
224+
@[inline, inherit_doc Iter.findSomeM?]
215225
def Iter.Partial.findSomeM? {α β : Type w} {γ : Type x} {m : Type x → Type w'} [Monad m]
216226
[Iterator α Id β] [IteratorLoopPartial α Id m] (it : Iter.Partial (α := α) β)
217227
(f : β → m (Option γ)) :
@@ -221,36 +231,50 @@ def Iter.Partial.findSomeM? {α β : Type w} {γ : Type x} {m : Type x → Type
221231
| none => return .yield none
222232
| some fx => return .done (some fx))
223233

234+
/--
235+
Steps through the iterator until `f` returns `some` for an element, at which point iteration stops
236+
and the result of `f` is returned. If the iterator is completely consumed without `f` returning
237+
`some`, then the result is `none`.
238+
-/
224239
@[inline]
225240
def Iter.findSome? {α β : Type w} {γ : Type x} [Iterator α Id β]
226241
[IteratorLoop α Id Id] [Finite α Id] (it : Iter (α := α) β) (f : β → Option γ) :
227242
Option γ :=
228243
Id.run (it.findSomeM? (pure <| f ·))
229244

230-
@[inline]
245+
@[inline, inherit_doc Iter.findSome?]
231246
def Iter.Partial.findSome? {α β : Type w} {γ : Type x} [Iterator α Id β]
232247
[IteratorLoopPartial α Id Id] (it : Iter.Partial (α := α) β) (f : β → Option γ) :
233248
Option γ :=
234249
Id.run (it.findSomeM? (pure <| f ·))
235250

251+
/--
252+
Steps through the iterator until an element satisfies the monadic predicate `f`, at which point
253+
iteration stops and the element is returned. If no element satisfies `f`, then the result is
254+
`none`.
255+
-/
236256
@[inline]
237257
def Iter.findM? {α β : Type w} {m : Type w → Type w'} [Monad m] [Iterator α Id β]
238258
[IteratorLoop α Id m] [Finite α Id] (it : Iter (α := α) β) (f : β → m (ULift Bool)) :
239259
m (Option β) :=
240260
it.findSomeM? (fun x => return if (← f x).down then some x else none)
241261

242-
@[inline]
262+
@[inline, inherit_doc Iter.findM?]
243263
def Iter.Partial.findM? {α β : Type w} {m : Type w → Type w'} [Monad m] [Iterator α Id β]
244264
[IteratorLoopPartial α Id m] (it : Iter.Partial (α := α) β) (f : β → m (ULift Bool)) :
245265
m (Option β) :=
246266
it.findSomeM? (fun x => return if (← f x).down then some x else none)
247267

268+
/--
269+
Steps through the iterator until an element satisfies `f`, at which point iteration stops and the
270+
element is returned. If no element satisfies `f`, then the result is `none`.
271+
-/
248272
@[inline]
249273
def Iter.find? {α β : Type w} [Iterator α Id β] [IteratorLoop α Id Id]
250274
[Finite α Id] (it : Iter (α := α) β) (f : β → Bool) : Option β :=
251275
Id.run (it.findM? (pure <| .up <| f ·))
252276

253-
@[inline]
277+
@[inline, inherit_doc Iter.find?]
254278
def Iter.Partial.find? {α β : Type w} [Iterator α Id β] [IteratorLoopPartial α Id Id]
255279
(it : Iter.Partial (α := α) β) (f : β → Bool) : Option β :=
256280
Id.run (it.findM? (pure <| .up <| f ·))

0 commit comments

Comments
 (0)