Skip to content

Commit fb79bd2

Browse files
committed
Test: improve comments
1 parent a626c6b commit fb79bd2

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

test/Inputs/Swiftskell.swift

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,8 @@ public struct Box<Wrapped: ~Copyable>: ~Copyable {
164164

165165

166166
/// MARK: Data.List
167+
///
168+
/// A singly-linked list
167169
public enum List<Element: ~Copyable>: ~Copyable {
168170
case cons(Element, Box<List<Element>>)
169171
case empty
@@ -179,7 +181,7 @@ public enum List<Element: ~Copyable>: ~Copyable {
179181
/// Pure Iteration
180182
extension List where Element: ~Copyable {
181183
/// Performs forward iteration through the list, accumulating a result value.
182-
/// Returns f(xn,...,f(x2, f(x1, init))...), or init if the list is empty.
184+
/// Returns f(xn,...,f(x2, f(x1, init))...), or `init` if the list is empty.
183185
public borrowing func foldl<Out>(
184186
init initial: consuming Out,
185187
_ f: (borrowing Element, consuming Out) -> Out) -> Out
@@ -196,7 +198,7 @@ extension List where Element: ~Copyable {
196198
}
197199

198200
/// Performs reverse iteration through the list, accumulating a result value.
199-
/// Returns f(x1, f(x2,...,f(xn, init)...)) or init if the list is empty.
201+
/// Returns f(x1, f(x2,...,f(xn, init)...)) or `init` if the list is empty.
200202
public borrowing func foldr<Out>(
201203
init initial: consuming Out,
202204
_ f: (borrowing Element, consuming Out) -> Out) -> Out
@@ -239,6 +241,8 @@ extension List where Element: ~Copyable {
239241
/// Basic utilities
240242
extension List where Element: ~Copyable {
241243
/// Is this list empty?
244+
///
245+
/// Complexity: O(1)
242246
public var isEmpty: Bool {
243247
borrowing get {
244248
switch self {
@@ -249,24 +253,32 @@ extension List where Element: ~Copyable {
249253
}
250254

251255
/// How many elements are in this list?
256+
///
257+
/// Complexity: O(n)
252258
public borrowing func length() -> Int {
253259
return foldl(init: 0) { $1 + 1 }
254260
}
255261

256262
/// Pop the first element off the list, if present.
263+
///
264+
/// Complexity: O(1)
257265
public consuming func pop() -> Optional<Pair<Element, List<Element>>> {
258266
switch consume self {
259267
case .empty: .none
260268
case let .cons(elm, tail): .pair(elm, tail.take())
261269
}
262270
}
263271

264-
/// Push an element onto the list.
272+
/// Push an element onto the front of the list.
273+
///
274+
/// Complexity: O(1)
265275
public consuming func push(_ newHead: consuming Element) -> List<Element> {
266276
return List(newHead, self)
267277
}
268278

269279
/// Produces a new list that is the reverse of this list.
280+
///
281+
/// Complexity: O(n)
270282
public consuming func reverse() -> List<Element> {
271283
var new = List<Element>()
272284
while case let .pair(head, tail) = pop() {

0 commit comments

Comments
 (0)