new Record()
The Record monoid. Record can be used to combine multiple key-value pairs into a single one by merging
- Version:
- 3.0.0
- Source:
Example
const {Record} = require('futils').monoid;
Record({foo: 1}); // -> Record({ foo :: 1 })
Record({foo: 1}).value; // -> { foo :: 1 }
Extends
- module:generics/Show
- module:generics/Eq
- module:generics/Ord
Methods
(static) empty() → {Record}
Monoid implementation for Record. Returns a Record of a empty key-value pair
- Source:
Returns:
- Type:
-
Record
The empty Record
Example
const {Record} = require('futils').monoid;
Record.empty(); // -> Record({})
(static) of(a) → {Record}
Lifts a value into a Record. Returns the empty Record for values which are no key-value pairs
- Source:
Parameters:
Name | Type | Description |
---|---|---|
a |
any
|
The value to lift |
Returns:
- Type:
-
Record
A new Record
Example
const {Record} = require('futils').monoid;
Record.of({foo: 1}); // -> Record({ foo :: 1 })
Record.of(null); // -> Record({})
Record.of((a) => a * 2); // -> Record({})
concat(a) → {Record}
Concatenates a Record with another by merging key-value pairs. Please note that this operation might loose data because it overrides fields with the same keys
- Source:
Parameters:
Name | Type | Description |
---|---|---|
a |
Record
|
The Record instance to concatenate with |
Returns:
- Type:
-
Record
A new Record
Example
const {Record} = require('futils').monoid;
const kv = Record({foo: 1});
kv.concat(Record({bar: 2}); // -> Record({ foo :: 1, bar :: 2 })
kv.concat(Record({foo: 2}); // -> Record({ foo :: 2 })