0.0.20 • Published 4 years ago

montainer v0.0.20

Weekly downloads
1
License
Apache-2.0
Repository
github
Last release
4 years ago

Montainer

Montainer types Listop and Dictop provide convenient methods for working with arrays and dicts (JS objects).

const tmp = Dictop.of(myState.foo).do().some().operations();
myState.foo = tmp.unwrap();
myState.error = tmp.getError();
Dictop.of(myState.foo).do().some().operations().done(
    (v) => {
        myState.foo = v;
    },
    (err) => {
        myState.foo = undefined;
        myState.error = err;
    }
);

Error handling

Errors detected by Montainer types are not thrown but rather set as property of a resulting instance. You can either test the result manually using .hasError() / .getError() methods or you can use method done(ok:(v)=>void, err:(e)=>void) to perform operations based on the result state.

Examples

Listop.of([{name: 'John Doe', reads: [10, 17, 19]}, {name: 'Jane Doe', reads: [3, 5, 21]}])
    .flatMap(user => Listop.of(user.reads))  // now we have [10, 17, 19, 3, 5, 21]
    .find(v => v === 17)
    .unwrapFirst();
Dictop.of({'19e2f7': {time: 10}, '2518af': {time: 13}, '5abfdd': {time: 27}})
    .map((item, _) => ({time: item.time + 1})
    .unwrap();

// produces: {'19e2f7': {time: 11}, '2518af': {time: 14}, '5abfdd': {time: 28}}
0.0.20

4 years ago

0.0.15

5 years ago

0.0.14

5 years ago

0.0.13

5 years ago

0.0.12

5 years ago

0.0.11

5 years ago

0.0.10

5 years ago

0.0.8

5 years ago

0.0.7

5 years ago

0.0.5

5 years ago

0.0.3

5 years ago

0.0.1

5 years ago