summary refs log tree commit diff stats
path: root/lib/std/with.nim
Commit message (Collapse)AuthorAgeFilesLines
* Small doc improvements for `std/with` (#17556)konsumlamm2021-03-291-3/+4
|
* use single backtick (#17141)flywind2021-02-211-1/+1
|
* move rest of tests to testament (#16140)flywind2020-11-271-20/+0
| | | | * move rest of tests to testament * Update tests/stdlib/tsums.nim
* std/with support field assign (#14484)slangmgh2020-08-151-0/+7
| | | | | | | | | | | | | | | | | | | | | * std/with support filed assign * add changelog * add support x.dup.with * add example * revert support x.dup.with; add example * update changelog; fix assignment in parameter * Update changelog.md * add example for assignment in parameter * Remove colon style assign Co-authored-by: Clyybber <darkmine956@gmail.com>
* fixes a bug for 'dup' and 'with'; they can now handle nested statement lists ↵Araq2020-03-171-8/+1
| | | | that can result from macros
* added operateOn to sugar.nim to give Nim the chaining mechanism it de… ↵Andreas Rumpf2020-02-261-0/+58
(#13092) * implemented the with stdlib module as specified in https://github.com/nim-lang/RFCs/issues/193 * change sugar.outplace to sugar.dup according to https://github.com/nim-lang/RFCs/issues/193 * changelog update
#fff0f0 } /* Literal.String.Interpol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
# All and any

template all(container, cond: untyped): bool =
  block:
    var result = true
    for it in items(container):
      if not cond(it):
        result = false
        break
    result

template any(container, cond: untyped): bool =
  block:
    var result = false
    for it in items(container):
      if cond(it):
        result = true
        break
    result

if all("mystring", {'a'..'z'}.contains) and any("myohmy", 'y'.`==`):
  echo "works"
else:
  echo "does not work"