Skip to content

Releases: Byloth/core

v1.3.0

24 Feb 17:57
d6f9e09
Compare
Choose a tag to compare

Minor release

Added new Aggregator class

Aggregator<T> is a class that extends SmartIterator<T> and allows the user to perform some transformation over elements of type <T>.
It allows you to group elements by a key of type <K>, filter them, map them to new values and/or reduce them to other objects and eventually materialize them again into new T[][], Map<K, T[]> or Record<K, T[]> objects.

Improved SmartIterator class

Added methods and functionalities to SmartIterator objects: enumerate, unique & count.

  • enumerate takes its behavior from Python's enumerate method: iterates over the original SmartIterator<T> returning a new SmartIterator<[number, T]> containing the index and value pairs of the original iterator.
  • unique consumes the original SmartIterator<T> returning a new SmartIterator<T> guaranteeing that it will only contain unique values.
  • count consumes the original SmartIterator<T> returning the number of elements it contains.

Added new Random class

The previous random utility function has been removed.
Now there's the new Random class now with some static methods: Boolean, Integer, Decimal and Choice.

  • Boolean generates a boolean value; optionally, you can specify the percentage of return of a true value.
  • Integer generates an integer value between two different values.
  • Decimal generates a decimal value between two different values.
  • Choice takes an array of elements and returns a random element from it.

Added a new utility function

Added the new enumerate utility function that takes some elements of type T and returns a new SmartIterator<[number, T]> containing the index and value pairs of the original iterator.

v1.3.0-rc.2

02 Feb 10:16
4f07344
Compare
Choose a tag to compare
v1.3.0-rc.2 Pre-release
Pre-release

Release Candidate

  • Added platform-indipendent Interval and Timeout return types.

v1.3.0.-rc.1

24 Jan 15:18
f69fe30
Compare
Choose a tag to compare
v1.3.0.-rc.1 Pre-release
Pre-release

Release Candidate

  • Removed random utility function while implemented a new Random class.

v1.2.1-rc.1

22 Jan 21:26
75499f8
Compare
Choose a tag to compare
v1.2.1-rc.1 Pre-release
Pre-release

Release Candidate

  • Improved SmartIterator class with count, enumerate & unique methods.
  • Added enumerate utility function.
  • Added Aggregator class.
  • Added AggregatedIterator class.
  • Added ReducedIterator class.

v1.2.0

04 Jan 15:04
660df90
Compare
Choose a tag to compare

Minor release

Added SmartIterator class

SmartIterator is a class that implements the Iterable and Iterator interface standards.
It can be used transparently as an Iterable or an Iterator plane object while still allowing you to call some functional-oriented methods that -until now- were reserved only for Array obejcts:

  • filter, map & reduce.
  • forEach.
  • every & some.

Calling these methods consumes the SmartIterator itself while it performs the operation and/or returns a result; the filter and map functions -of course- return a new SmartIterator instance based on their predicate argument.

Initialization

To instanciate a new SmartIterator object, simply call the constructor by passing an Iterable or an Iterator object or by defining a new GeneratorFunction inline.

Here some examples...

... based on an Array object:

const smartIteratorObj = new SmartIterator([0, 2, 4, 6, 8]);

... based on an Iterable object:

const hashmapObj = new Map();

// [...]

const smartIteratorObj = new SmartIterator(hashmapObj.values());

... based on an Iterator object:

function* fibonacci(start = 0) {
    let a = start;
    let b = 1;

    while (true) {
        yield a;
        [a, b] = [b, a + b];
    }
}

const iteratorObj = fibonacci(8);
const smartIteratorObj = new SmartIterator(iteratorObj);

... based on an inline GeneratorFunction:

const smartIteratorObj = new SmartIterator(function* () {
    for (let i = 0; i < 10; i +=1) {
        yield i;
    }
});

Convert to an Array

Whenever you need to materialize it into an Array object, simply call the toArray method.
Be careful of the infinite generators (e.g. Fibonacci's sequence)!

Support for next with parameters, returns & throws methods

It also supports Iterator objects with these types of non-nullish properties.
Objects with non-null next parameters won't be Iterable and using them in for-of statements will return a TypeScript error (unlike standard Iterator objects).

Improved support & Backward compatibility

Library functions like range, unique or zip that were previously GeneratorFunction objects, now return an instance of the new SmartIterator class. This won't affect previous implementations.

v1.2.0-rc.3

27 Dec 17:42
0999dc1
Compare
Choose a tag to compare
v1.2.0-rc.3 Pre-release
Pre-release

Release Candidate

  • Added every and some methods to SmartIterator class.

v1.2.0-rc.2

22 Dec 11:23
60575fb
Compare
Choose a tag to compare
v1.2.0-rc.2 Pre-release
Pre-release

Release Candidate

  • Added toArray method on SmartIterator objects.

v1.2.0-rc.1

21 Dec 15:45
5595a40
Compare
Choose a tag to compare
v1.2.0-rc.1 Pre-release
Pre-release

Release Candidate

  • Implemented class SmartIterator which is a normal JS iterator that allows you to use filter, map, reduce and forEach functions on it.
  • Library functions that previously returned some sort of Iterable object, now return a SmartIterator object.

v1.1.8

12 Dec 15:53
447d449
Compare
Choose a tag to compare

Patch release

  • Added average function (also capable of weighted average).
  • Added zip function (inspired by the Python's one).

v1.1.7

22 Nov 10:03
49249d1
Compare
Choose a tag to compare

Patch release

  • Improved support for bundlers other than Vite.js.