Skip to content

Commit

Permalink
dev
Browse files Browse the repository at this point in the history
  • Loading branch information
fgaudo committed Aug 28, 2024
1 parent e9761c5 commit b8cfd7e
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 53 deletions.
10 changes: 3 additions & 7 deletions src/core/non-empty-hash-set.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,15 @@ import {
nonEmpty,
} from 'effect/NonEmptyIterable'

import { HS, O } from './imports'
import {
type PositiveInteger,
unsafe_fromNumber,
} from './integer/positive'
import { HS, O, PInt } from './imports'

export type NonEmptyHashSet<A> = HS.HashSet<A> &
NonEmptyIterable<A>

export const size = <A>(
hashSet: NonEmptyHashSet<A>,
): PositiveInteger =>
unsafe_fromNumber(HS.size(hashSet))
): PInt.PositiveInteger =>
PInt.unsafe_fromNumber(HS.size(hashSet))

export const fromHashSet = <A>(
hashSet: HS.HashSet<A>,
Expand Down
49 changes: 15 additions & 34 deletions src/core/non-empty-trimmed-string.ts
Original file line number Diff line number Diff line change
@@ -1,43 +1,24 @@
import { O, Ord } from './imports'
import { B, O } from './imports'

const stringSymbol: unique symbol = Symbol()
const _: unique symbol = Symbol()

export interface NonEmptyTrimmedString {
[stringSymbol]: string
}

export const fromString = (string: string) =>
O.gen(function* () {
const str = string.trim()
if (!isNonBlank(str)) {
return yield* O.none()
}
export type NonEmptyTrimmedString = string &
B.Brand<typeof _>

return { [stringSymbol]: str }
})

export const toString = (
string: NonEmptyTrimmedString,
) => string[stringSymbol]
export const isNonBlank = (string: string) =>
/\S/.test(string)

export const unsafe_fromString = (
string: string,
value: string,
) => {
const str = string.trim()
const string = value.trim()

if (!isNonBlank(str)) {
throw new Error('Not a non-empty string')
}
return { [stringSymbol]: str }
return B.refined<NonEmptyTrimmedString>(
isNonBlank,
() => B.error('String is blank'),
)(string)
}

export const isNonBlank = (string: string) =>
/\S/.test(string)

export const order: Ord.Order<
NonEmptyTrimmedString
> = (self, that) =>
Ord.string(
self[stringSymbol],
that[stringSymbol],
)
export const fromString = O.liftThrowable(
unsafe_fromString,
)
4 changes: 2 additions & 2 deletions src/data/capacitor/write/add-product.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { tryPromise } from '@/core/helper'
import { E, Eff, NETS, O } from '@/core/imports'
import { E, Eff, O } from '@/core/imports'

import {
type AddProductDTO,
Expand All @@ -21,7 +21,7 @@ export const command: (
const result = yield* tryPromise(() =>
db.addProduct({
product: {
name: NETS.toString(product.name),
name: product.name,
creationDate: product.creationDate,
expirationDate: O.isSome(
product.expirationDate,
Expand Down
3 changes: 1 addition & 2 deletions src/data/mock/read/get-sorted-products.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import {
A,
Eff,
NETS,
NNInt,
O,
Ord,
Expand Down Expand Up @@ -41,7 +40,7 @@ const ord = Ord.make(
),
),
pipe(
NETS.order,
Ord.string,
Ord.mapInput(
(product: typeof p1) => product.name,
),
Expand Down
4 changes: 2 additions & 2 deletions src/ui/pages/Home/components/Item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
Switch,
} from 'solid-js'

import { HS, Int, NETS, O } from '@/core/imports'
import { HS, Int, O } from '@/core/imports'

import type { ProductModel } from '@/app/use-cases/get-sorted-products'

Expand Down Expand Up @@ -314,7 +314,7 @@ const Button: Component<{
return O.isSome(name) && name.value
})()}
fallback="CORRUPTED">
{name => NETS.toString(name())}
{name => name()}
</Show>
</div>
</mdui-list-item>
Expand Down
8 changes: 2 additions & 6 deletions src/ui/widgets/SnackBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,7 @@ export const Snackbar: Component<{
{(() => {
const res = toast()
if (O.isSome(res)) {
return NETS.toString(
res.value[1][1],
)
return res.value[1][1]
}
return ''
})()}
Expand Down Expand Up @@ -169,9 +167,7 @@ export const Snackbar: Component<{
{(() => {
const res = toast()
if (O.isSome(res)) {
return NETS.toString(
res.value[1][1],
)
return res.value[1][1]
}
return ''
})()}
Expand Down

0 comments on commit b8cfd7e

Please sign in to comment.