new.counter: Create new Counter

View source: R/yogitools.R

new.counterR Documentation

Create new Counter

Description

This constructor method creates an object that can count occurrences of different items. It allows importing and exporting of the counter status in string form.

Usage

new.counter()

Details

The object has the following methods:

  • inc(id): Increase the counter for item with id by 1.

  • add(id,x): Add x occurrences for the item with id.

  • get(id): Get the number of occurrences seen for item id.

  • ls(id): List all counts for all items by id.

  • export(id): Exports the counter state to a string that can be saved or logged.

  • import.add(str) Imports a previous counter state from the string str and adds it to the current counts.

Value

An object of type yogicounter.

Examples

cn <- new.counter()
cn$inc("foo")
cn$inc("bar")
cn$add("foo",6)
cn$get("foo")
# 7
cn$ls()
# foo 7
# bar 1
cn$export()
# foo=7,bar=1

jweile/yogitools documentation built on May 11, 2023, 7:42 p.m.