Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- proc partition*[T](s: openArray[T], pred: proc(x: T): bool {.closure.}): tuple[t: seq[T], f: seq[T]] {.inline.} =
- ## nim doc this_file.nim
- ## fails with an error
- ## However, if you remove these 3 doc comments, the problem disappears.
- runnableExamples:
- let
- temperatures = @[-272.15, -2.0, 24.5, 44.31, 99.9, -113.44]
- partitions = temperatures.partition(proc(x: float): bool = x < 50.0 and x > -10.0)
- assert partitions[0] == @[-2.0, 24.5, 44.31]
- assert partitions.t == partitions[0]
- assert partitions[1] == @[-272.15, 99.9, -113.44]
- assert partitions.f == partitions[1]
- var
- t = newSeq[T]()
- f = newSeq[T]()
- for i in 0 ..< s.len:
- if pred(s[i]):
- t &= s[i]
- else:
- f &= s[i]
- (t: t, f: f)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement