Advertisement
Guest User

Untitled

a guest
Oct 17th, 2018
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Nim 0.76 KB | None | 0 0
  1. proc partition*[T](s: openArray[T], pred: proc(x: T): bool {.closure.}): tuple[t: seq[T], f: seq[T]] {.inline.} =
  2.   ## nim doc this_file.nim
  3.   ## fails with an error
  4.   ## However, if you remove these 3 doc comments, the problem disappears.
  5.   runnableExamples:
  6.     let
  7.       temperatures = @[-272.15, -2.0, 24.5, 44.31, 99.9, -113.44]
  8.       partitions = temperatures.partition(proc(x: float): bool = x < 50.0 and x > -10.0)
  9.     assert partitions[0] == @[-2.0, 24.5, 44.31]
  10.     assert partitions.t == partitions[0]
  11.     assert partitions[1] == @[-272.15, 99.9, -113.44]
  12.     assert partitions.f == partitions[1]
  13.  
  14.   var
  15.     t = newSeq[T]()
  16.     f = newSeq[T]()
  17.   for i in 0 ..< s.len:
  18.     if pred(s[i]):
  19.       t &= s[i]
  20.     else:
  21.       f &= s[i]
  22.   (t: t, f: f)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement