21 lines
553 B
Nim
21 lines
553 B
Nim
import std/options, std/sugar, std/tables
|
|
|
|
func sameContents*[T](a: seq[T], b: seq[T]): bool =
|
|
let aCount = toCountTable(a)
|
|
let bCount = toCountTable(b)
|
|
|
|
for k in aCount.keys:
|
|
if not bCount.hasKey(k) or aCount[k] != bCount[k]: return false
|
|
|
|
return aCount.len == bCount.len
|
|
|
|
func findBy*[T](s: seq[T], operation: (T) -> bool): Option[T] =
|
|
for i in s:
|
|
if operation(i):
|
|
return some(i)
|
|
return none[T]()
|
|
|
|
proc mapById*[T](records: seq[T]): TableRef[string, T] =
|
|
result = newTable[string, T]()
|
|
for r in records: result[r.id] = r
|