Skip to content

Instantly share code, notes, and snippets.

@def-
Created March 9, 2016 13:42
Show Gist options
  • Save def-/e393b7f944ea75082186 to your computer and use it in GitHub Desktop.
Save def-/e393b7f944ea75082186 to your computer and use it in GitHub Desktop.
var xs: seq[tuple[nr: int, name: string]] = @[(1, "foo"), (2, "bar"), (3, "foobar"), (0, "baz")]
# Imperatively:
var max = xs[0]
for i in 1 .. xs.high:
if xs[i].nr > max.nr:
max = xs[i]
echo max
# Functionally:
import sequtils
echo xs.foldl(if a.nr > b.nr: a else: b)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment