~reesmichael1/roman

ref: 3784df6eb213fc0ccd683ed396d42645e1bca718 roman/src/romanpkg/seqreplace.nim -rw-r--r-- 345 bytes
3784df6eMichael Rees Fix crash when displaying very long link in post 5 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
import sequtils


proc replace*[T](s: var seq[T], old: T, updated: T) =
  var elementIx = -1
  for ix, element in s:
    if element == old:
      elementIx = ix
  if elementIx == -1:
    raise newException(KeyError, "could not find post in feed post list")

  s.keepIf(proc (element: T): bool = element != old)
  s.insert(@[updated], elementIx)