From 0ef7baa73961615aaec5087b8f450a12e7c67656 Mon Sep 17 00:00:00 2001 From: Matei Adriel Date: Mon, 23 Dec 2019 15:08:36 +0200 Subject: [PATCH] typescript(option): refactor: now using @thi.ng/compose Signed-off-by: prescientmoon --- typescript/option/package.json | 1 + typescript/option/pnpm-lock.yaml | 17 +++++++++++++++++ typescript/option/src/helpers/count.ts | 4 ++-- typescript/option/src/helpers/flat.ts | 2 +- typescript/option/src/helpers/map.ts | 3 ++- typescript/option/src/helpers/toNullable.ts | 2 +- typescript/option/src/helpers/withDefault.ts | 2 +- typescript/option/src/internals.ts | 2 -- typescript/option/src/types.ts | 3 ++- 9 files changed, 27 insertions(+), 9 deletions(-) diff --git a/typescript/option/package.json b/typescript/option/package.json index 3883c57..c98aa4e 100644 --- a/typescript/option/package.json +++ b/typescript/option/package.json @@ -38,6 +38,7 @@ "author": "Matei Adriel", "license": "SEE LICENSE IN LICENSE", "dependencies": { + "@thi.ng/compose": "^1.3.6", "tslib": "^1.10.0" } } diff --git a/typescript/option/pnpm-lock.yaml b/typescript/option/pnpm-lock.yaml index 79b59ec..3271d76 100644 --- a/typescript/option/pnpm-lock.yaml +++ b/typescript/option/pnpm-lock.yaml @@ -1,4 +1,5 @@ dependencies: + '@thi.ng/compose': 1.3.6 tslib: 1.10.0 devDependencies: '@rollup/plugin-commonjs': 11.0.0_rollup@1.27.14 @@ -953,6 +954,21 @@ packages: semantic-release: '>=15.8.0 <16.0.0 || >=16.0.0-beta <17.0.0' resolution: integrity: sha512-LGjgPBGjjmjap/76O0Md3wc04Y7IlLnzZceLsAkcYRwGQdRPTTFUJKqDQTuieWTs7zfHzQoZqsqPfFxEN+g2+Q== + /@thi.ng/api/6.6.0: + dev: false + resolution: + integrity: sha512-CG4jxoidxdTNAVdGEGj9nLwOts37BszTWSl3RejFL/K2yOxEkB77c0zfvz19sSZVfUWv5dDWgXewbYwBnHvKlA== + /@thi.ng/compose/1.3.6: + dependencies: + '@thi.ng/api': 6.6.0 + '@thi.ng/errors': 1.2.2 + dev: false + resolution: + integrity: sha512-anCFAQqnfOjPXGkkAptJE9gMBtD4jMJc/2sETLl09M3BUMCj3i6We1tCJ9ljcoXwO+jgscTAaMOopiOwslO0SA== + /@thi.ng/errors/1.2.2: + dev: false + resolution: + integrity: sha512-M0T8m+H+FDAFi6Oe8FTYQWTBgx+xrwsstiH4KzSUGjDGmJ7Hi/FSfwmBPIslrRVnrnJKwBk41aYQ1tk3J6CNKw== /@types/color-name/1.1.1: dev: true resolution: @@ -3631,6 +3647,7 @@ packages: specifiers: '@rollup/plugin-commonjs': ^11.0.0 '@rollup/plugin-node-resolve': ^6.0.0 + '@thi.ng/compose': ^1.3.6 '@types/node': ^12.12.21 '@wessberg/rollup-plugin-ts': ^1.1.83 rimraf: ^3.0.0 diff --git a/typescript/option/src/helpers/count.ts b/typescript/option/src/helpers/count.ts index 4f8c017..6cdb30d 100644 --- a/typescript/option/src/helpers/count.ts +++ b/typescript/option/src/helpers/count.ts @@ -1,4 +1,4 @@ -import { Option } from '../types' import { isSome } from './isSome' +import { compL } from '@thi.ng/compose' -export const count = (option: Option) => Number(isSome(option)) +export const count = compL(isSome, Number) diff --git a/typescript/option/src/helpers/flat.ts b/typescript/option/src/helpers/flat.ts index e23283b..0d5f1f2 100644 --- a/typescript/option/src/helpers/flat.ts +++ b/typescript/option/src/helpers/flat.ts @@ -1,5 +1,5 @@ import { bind } from './bind' -import { identity } from '../internals' +import { identity } from '@thi.ng/compose' import { Option } from '../types' export const flat = (option: Option>): Option => { diff --git a/typescript/option/src/helpers/map.ts b/typescript/option/src/helpers/map.ts index 672b6a8..01f850b 100644 --- a/typescript/option/src/helpers/map.ts +++ b/typescript/option/src/helpers/map.ts @@ -1,10 +1,11 @@ import { match } from './match' import { Mapper } from '../internalTypes' import { Option, Some, None } from '../types' +import { compL } from '@thi.ng/compose' export const map = ( mapper: Mapper, option: Option ): Option => { - return match(v => Some(mapper(v)), None, option) + return match(compL(mapper, Some), None, option) } diff --git a/typescript/option/src/helpers/toNullable.ts b/typescript/option/src/helpers/toNullable.ts index 07baa84..7a7d072 100644 --- a/typescript/option/src/helpers/toNullable.ts +++ b/typescript/option/src/helpers/toNullable.ts @@ -1,5 +1,5 @@ import { match } from './match' -import { identity } from '../internals' +import { identity } from '@thi.ng/compose' import { Option } from '../types' export const toNullable = (option: Option) => { diff --git a/typescript/option/src/helpers/withDefault.ts b/typescript/option/src/helpers/withDefault.ts index b9c0f6d..b1c9934 100644 --- a/typescript/option/src/helpers/withDefault.ts +++ b/typescript/option/src/helpers/withDefault.ts @@ -1,5 +1,5 @@ import { match } from './match' -import { identity } from '../internals' +import { identity } from '@thi.ng/compose' import { Option } from '../types' export const withDefault = (_default: T, option: Option) => { diff --git a/typescript/option/src/internals.ts b/typescript/option/src/internals.ts index 54e7cd7..09b8392 100644 --- a/typescript/option/src/internals.ts +++ b/typescript/option/src/internals.ts @@ -1,3 +1 @@ -export const identity = (v: T) => v - export const none = Symbol('none') diff --git a/typescript/option/src/types.ts b/typescript/option/src/types.ts index 005e415..397841e 100644 --- a/typescript/option/src/types.ts +++ b/typescript/option/src/types.ts @@ -1,5 +1,6 @@ -import { none, identity } from './internals' +import { identity } from '@thi.ng/compose' import { Brand } from 'utility-types' +import { none } from './internals' // This is never actually used outside of typing so we can just declare it declare const some: unique symbol