https://github.com/sysgears/fractal-objects
Fractal Objects - self-similar objects that can be multiplied together and the result will be a fractal object and have the same type and shape as multiplicands.
https://github.com/sysgears/fractal-objects
Last synced: about 1 year ago
JSON representation
Fractal Objects - self-similar objects that can be multiplied together and the result will be a fractal object and have the same type and shape as multiplicands.
- Host: GitHub
- URL: https://github.com/sysgears/fractal-objects
- Owner: sysgears
- License: mit
- Created: 2018-09-29T12:05:33.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2023-01-03T19:43:51.000Z (over 3 years ago)
- Last Synced: 2025-03-04T17:48:57.463Z (over 1 year ago)
- Language: TypeScript
- Homepage:
- Size: 973 KB
- Stars: 2
- Watchers: 3
- Forks: 1
- Open Issues: 12
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Fractal Objects
[](https://twitter.com/sysgears)
## Example
```javascript
// Fractal object #1
const part1 = { arrayKey: [1], objectKey: { a: 'a', b: 'b' } };
// Fractal object #2
const part2 = { arrayKey: [2, 3], objectKey: { c: 'c' } };
// Fractal object #3
const part3 = { arrayKey: [4] }
// View the result of the multiplication of the fractal objects #1, #2, and #3
console.log(fold([part1, part2, part3]));
// The output is a new fractal object:
// { arrayKey: [ 1, 2, 3, 4 ], objectKey: { a: 'a', b: 'b', c: 'c' } }
```
## Concept
A fractal object is an object that has self-similarity at lower scales. Multiplication of two fractal objects results in a new fractal object that has the same shape as the original ones.
If we multiply fractal objects in a list pairwise, we'll receive a new fractal object, which will represent all the fractal objects in the list and which will also have the same shape.
By default, the multiplication function provided by the `fractal-objects` package multiplies two objects by concatenating their array values, merging object values, and replacing scalars with
values from the second multiplied object.
Any other multiplication function can be used if it has the following properties:
1. It _keeps the object shape_: The multiplicands and the result must have the same shape and type.
2. It's _associative_. For example, multiplying `(a b) c` must have the same result as multiplying `a (b c)`.
3. It must yield the result `a` when multiplying `undefined a` or `a undefined`.
In terms of mathematics, fractal objects are a _[semigroup]_.
## Usage
Fractal Objects currently have implementations for these programming languages:
- [TypeScript](/typescript)
- [Scala](/scala)
## License
Copyright © 2018 [SysGears (Cyprus) Limited]. This source code is licensed under the [MIT] license.
[MIT]: LICENSE
[SysGears (Cyprus) Limited]: http://sysgears.com
[commutative semigroup]: https://en.wikipedia.org/wiki/Semigroup