Skip to content

Commit

Permalink
chore: Update versions
Browse files Browse the repository at this point in the history
  • Loading branch information
patroza committed Dec 7, 2024
1 parent c74c69d commit ed995e3
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 54 deletions.
6 changes: 6 additions & 0 deletions packages/effect-app/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# @effect-app/prelude

## 2.19.4

### Patch Changes

- fix: return type

## 2.19.3

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/effect-app/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "effect-app",
"version": "2.19.3",
"version": "2.19.4",
"license": "MIT",
"type": "module",
"dependencies": {
Expand Down
57 changes: 6 additions & 51 deletions packages/effect-app/src/Array.ts
Original file line number Diff line number Diff line change
@@ -1,70 +1,39 @@
import type { Order } from "effect"
import { Chunk, Effect } from "effect"
import type { NonEmptyArray, NonEmptyReadonlyArray } from "effect/Array"
import * as Array from "effect/Array"
import * as T from "effect/Effect"
import type { Predicate } from "./Function.js"
import { dual, identity, tuple } from "./Function.js"
import { dual, tuple } from "./Function.js"
import * as Option from "./Option.js"

/**
* @tsplus getter ReadonlyArray toNonEmpty
* @tsplus getter Array toNonEmpty
* @tsplus getter effect/data/ReadonlyArray toNonEmpty
*/
export const toNonEmptyArray = <A>(a: ReadonlyArray<A>): Option.Option<NonEmptyReadonlyArray<A>> =>
a.length ? Option.some(a as NonEmptyReadonlyArray<A>) : Option.none()
export const toNonEmptyArray = Option.liftPredicate(Array.isNonEmptyReadonlyArray)

export const isArray: {
// uses ReadonlyArray here because otherwise the second overload don't work when ROA is involved.
(self: unknown): self is ReadonlyArray<unknown>
<T>(self: T): self is Extract<T, ReadonlyArray<any>>
} = Array.isArray

/**
* @tsplus static effect/data/ReadonlyArray/NonEmptyArray.Ops fromArray
*/
export function NEAFromArray<T>(ar: Array<T>) {
return ar.length ? Option.some(ar as NonEmptyArray<T>) : Option.none()
}

/**
* @tsplus static effect/data/ReadonlyArray/NonEmptyArray.Ops fromArray
*/
export function NEROArrayFromArray<T>(ar: ReadonlyArray<T>) {
return ar.length ? Option.some(ar as NonEmptyReadonlyArray<T>) : Option.none()
}

/**
* @tsplus pipeable Array sortByO
* @tsplus pipeable ReadonlyArray sortByO
* @tsplus pipeable NonEmptyArray sortByO
* @tsplus pipeable NonEmptyArrayReadonlyArray sortByO
*/
export function sortByO<A>(
ords: Option.Option<NonEmptyReadonlyArray<Order.Order<A>>>
): (a: ReadonlyArray<A>) => ReadonlyArray<A> {
return Option.match(ords, { onNone: () => identity, onSome: (_) => Array.sortBy(..._) })
}

/**
* @tsplus fluent ReadonlyArray groupByT
* @tsplus fluent Array groupByT
* @tsplus fluent NonEmptyArray groupByT
* @tsplus fluent NonEmptyArrayReadonlyArray groupByT
*/
export const groupByT = dual<
<A, Key extends PropertyKey>(
f: (a: NoInfer<A>) => Key
) => (as: ReadonlyArray<A>) => ReadonlyArray<readonly [Key, NonEmptyReadonlyArray<A>]>,
) => (as: ReadonlyArray<A>) => Array<readonly [Key, NonEmptyArray<A>]>,
<A, Key extends PropertyKey>(
as: ReadonlyArray<A>,
f: (a: A) => Key
) => ReadonlyArray<readonly [Key, NonEmptyReadonlyArray<A>]>
) => Array<readonly [Key, NonEmptyArray<A>]>
>(2, <A, Key extends PropertyKey>(
as: ReadonlyArray<A>,
f: (a: A) => Key
): ReadonlyArray<readonly [Key, NonEmptyReadonlyArray<A>]> => {
): Array<readonly [Key, NonEmptyArray<A>]> => {
const r: Record<Key, Array<A> & { 0: A }> = {} as any
for (const a of as) {
const k = f(a)
Expand All @@ -75,22 +44,15 @@ export const groupByT = dual<
r[k] = [a]
}
}
return Object.entries(r).map(([k, items]) => tuple(k as unknown as Key, items as NonEmptyReadonlyArray<A>))
return Object.entries(r).map(([k, items]) => tuple(k as unknown as Key, items as NonEmptyArray<A>))
})

// A getter would be nice, but we need it fluent to manage the priority vs nonEmpty etc
/**
* @tsplus fluent ReadonlyArray randomElement 2
*/
export function randomElement<A>(a: NonEmptyReadonlyArray<A>): A
export function randomElement<A>(a: ReadonlyArray<A>): A | undefined
export function randomElement<A>(a: ReadonlyArray<A>): A | undefined {
return a[Math.floor(Math.random() * a.length)]
}

/**
* @tsplus fluent ReadonlyArray filterWith
*/
export function filterWith<A>(self: ReadonlyArray<A>, predicates: ReadonlyArray<Predicate<A>>) {
return self.filter((_) => predicates.every((f) => f(_)))
}
Expand All @@ -108,18 +70,11 @@ export function* _chunk_<T>(items_: Iterable<T>, size: number) {

/**
* Split the `items` array into multiple, smaller chunks of the given `size`.
* @tsplus fluent Array chunk
* @tsplus fluent ReadonlyArray chunk
* @tsplus fluent effect/data/Chunk chunk
* @tsplus fluent Iterable chunk
*/
export function chunk_<T>(items_: Iterable<T>, size: number) {
return Chunk.fromIterable(_chunk_(items_, size))
}

/**
* @tsplus fluent effect/data/ReadonlyArray/NonEmptyReadonlyArray forEachEffect
*/
export function forEachEffectNA<A, R, E, B>(as: NonEmptyReadonlyArray<A>, f: (a: A) => Effect.Effect<B, E, R>) {
return Effect.map(T.forEach(as, f), (_) => Option.getOrNull(toNonEmptyArray(_)))
}
Expand Down
7 changes: 7 additions & 0 deletions packages/infra/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# @effect-app/infra

## 2.31.2

### Patch Changes

- Updated dependencies
- effect-app@2.19.4

## 2.31.1

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/infra/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@effect-app/infra",
"version": "2.31.1",
"version": "2.31.2",
"license": "MIT",
"type": "module",
"dependencies": {
Expand Down
7 changes: 7 additions & 0 deletions packages/vue/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# @effect-app/vue

## 2.16.3

### Patch Changes

- Updated dependencies
- effect-app@2.19.4

## 2.16.2

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/vue/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@effect-app/vue",
"version": "2.16.2",
"version": "2.16.3",
"license": "MIT",
"type": "module",
"homepage": "https://github.com/effect-ts-app/libs/tree/main/packages/vue",
Expand Down

0 comments on commit ed995e3

Please sign in to comment.