Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Array.removeOption and Chunk.removeOption #4436

Open
wants to merge 19 commits into
base: next-minor
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
f5acf08
add RcMap.invalidate api, for removing a resource from an RcMap (#4278)
tim-smart Jan 17, 2025
2a04b9e
add RcMap.touch, for reseting the idle timeout for an item (#4281)
tim-smart Jan 17, 2025
1aaf89a
reduce churn of RcMap idle timeout fiber (#4282)
tim-smart Jan 17, 2025
e4bbbec
Add `Effect.transposeOption`, closes #3142 (#4284)
gcanti Jan 21, 2025
06da212
add Effect.filterEffect* apis (#4335)
tim-smart Jan 23, 2025
3f6e363
add {FiberHandle,FiberSet,FiberMap}.awaitEmpty apis (#4337)
tim-smart Jan 24, 2025
7439a52
`Differ` implements `Pipeable` (#4239)
KhraksMamtsov Jan 24, 2025
74b5c4f
Add `Effect.whenLogLevel` (#4342)
indietyp Jan 30, 2025
2262b0c
fix some tests using old assert
tim-smart Feb 1, 2025
8b5e01a
Relax `Trie` variance (#4338)
KhraksMamtsov Feb 4, 2025
8879ccc
Make it easy to convert a DateTime.Zoned to a DateTime.Utc (#4375)
thewilkybarkid Feb 4, 2025
e029e5c
add Promise based apis to Fiber{Handle,Set,Map} modules (#4401)
tim-smart Feb 5, 2025
7c8a5fc
Add `HashMap.some` (#4347)
LaureRC Feb 5, 2025
6001bda
add ISO8601 duration formatting (#4343)
fubhy Feb 5, 2025
c663773
Schema: Add `standardSchemaV1` API to Generate a Standard Schema (#4359)
gcanti Feb 5, 2025
83edb42
Add missing `Either.void` constructor (#4413)
gcanti Feb 6, 2025
6ba4a19
Add Layer.updateService mirroring Effect.updateService (#4421)
mikearnaldi Feb 9, 2025
4f82ba5
allow accessing args in Effect.fn pipe (#4417)
tim-smart Feb 10, 2025
5b2a094
Add Array.removeOption and Chunk.removeOption
thewilkybarkid Feb 11, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/chatty-terms-occur.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"effect": minor
---

add Promise based apis to Fiber{Handle,Set,Map} modules
31 changes: 31 additions & 0 deletions .changeset/cyan-radios-relate.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
---
"effect": minor
---

Add `Effect.transposeOption`, closes #3142.

Converts an `Option` of an `Effect` into an `Effect` of an `Option`.

**Details**

This function transforms an `Option<Effect<A, E, R>>` into an
`Effect<Option<A>, E, R>`. If the `Option` is `None`, the resulting `Effect`
will immediately succeed with a `None` value. If the `Option` is `Some`, the
inner `Effect` will be executed, and its result wrapped in a `Some`.

**Example**

```ts
import { Effect, Option } from "effect"

// ┌─── Option<Effect<number, never, never>>
// ▼
const maybe = Option.some(Effect.succeed(42))

// ┌─── Effect<Option<number>, never, never>
// ▼
const result = Effect.transposeOption(maybe)

console.log(Effect.runSync(result))
// Output: { _id: 'Option', _tag: 'Some', value: 42 }
```
5 changes: 5 additions & 0 deletions .changeset/dirty-ways-dress.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"effect": minor
---

Add `Effect.whenLogLevel`, which conditionally executes an effect if the specified log level is enabled
5 changes: 5 additions & 0 deletions .changeset/great-buses-perform.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"effect": minor
---

add RcMap.touch, for reseting the idle timeout for an item
5 changes: 5 additions & 0 deletions .changeset/loud-starfishes-grow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"effect": minor
---

Add HashMap.some
5 changes: 5 additions & 0 deletions .changeset/mighty-turtles-battle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"effect": minor
---

allow accessing args in Effect.fn pipe
5 changes: 5 additions & 0 deletions .changeset/new-numbers-visit.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"effect": minor
---

add RcMap.invalidate api, for removing a resource from an RcMap
5 changes: 5 additions & 0 deletions .changeset/polite-tables-cry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"effect": minor
---

Add Layer.updateService mirroring Effect.updateService
5 changes: 5 additions & 0 deletions .changeset/pretty-trainers-rescue.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"effect": patch
---

`Trie<out A>` type annotations have been aligned. The type parameter was made covariant because the structure is immutable.
5 changes: 5 additions & 0 deletions .changeset/rude-rules-brush.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"effect": minor
---

`Differ` implements `Pipeable`
5 changes: 5 additions & 0 deletions .changeset/six-pumpkins-yell.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"effect": minor
---

Add Array.removeOption and Chunk.removeOption
5 changes: 5 additions & 0 deletions .changeset/sixty-mice-occur.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"effect": minor
---

Make it easy to convert a DateTime.Zoned to a DateTime.Utc
5 changes: 5 additions & 0 deletions .changeset/thick-laws-yell.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"effect": minor
---

Add missing `Either.void` constructor.
5 changes: 5 additions & 0 deletions .changeset/tough-cars-invite.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"effect": minor
---

add {FiberHandle,FiberSet,FiberMap}.awaitEmpty apis
19 changes: 19 additions & 0 deletions .changeset/twenty-owls-hunt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
"effect": minor
---

Schema: Add `standardSchemaV1` API to Generate a [Standard Schema v1](https://standardschema.dev/).

**Example**

```ts
import { Schema } from "effect"

const schema = Schema.Struct({
name: Schema.String
})

// ┌─── StandardSchemaV1<{ readonly name: string; }>
// ▼
const standardSchema = Schema.standardSchemaV1(schema)
```
5 changes: 5 additions & 0 deletions .changeset/warm-bulldogs-grab.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"effect": minor
---

Added `Duration.formatIso` and `Duration.fromIso` for formatting and parsing ISO8601 durations.
56 changes: 56 additions & 0 deletions .changeset/warm-clouds-grab.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
---
"effect": minor
---

add Effect.filterEffect\* apis

#### Effect.filterEffectOrElse

Filters an effect with an effectful predicate, falling back to an alternative
effect if the predicate fails.

```ts
import { Effect, pipe } from "effect"

// Define a user interface
interface User {
readonly name: string
}

// Simulate an asynchronous authentication function
declare const auth: () => Promise<User | null>

const program = pipe(
Effect.promise(() => auth()),
// Use filterEffectOrElse with an effectful predicate
Effect.filterEffectOrElse({
predicate: (user) => Effect.succeed(user !== null),
orElse: (user) => Effect.fail(new Error(`Unauthorized user: ${user}`))
})
)
```

#### Effect.filterEffectOrFail

Filters an effect with an effectful predicate, failing with a custom error if the predicate fails.

```ts
import { Effect, pipe } from "effect"

// Define a user interface
interface User {
readonly name: string
}

// Simulate an asynchronous authentication function
declare const auth: () => Promise<User | null>

const program = pipe(
Effect.promise(() => auth()),
// Use filterEffectOrFail with an effectful predicate
Effect.filterEffectOrFail({
predicate: (user) => Effect.succeed(user !== null),
orFailWith: (user) => Effect.fail(new Error(`Unauthorized user: ${user}`))
})
)
```
10 changes: 10 additions & 0 deletions packages/effect/dtslint/Effect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1350,3 +1350,13 @@ hole<
}>
>
>()

// -------------------------------------------------------------------------------------
// transposeOption
// -------------------------------------------------------------------------------------

// $ExpectType Effect<Option<never>, never, never>
Effect.transposeOption(Option.none())

// $ExpectType Effect<Option<string>, "err-1", "dep-1">
Effect.transposeOption(Option.some(string))
1 change: 1 addition & 0 deletions packages/effect/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
"zod": "^3.24.1"
},
"dependencies": {
"@standard-schema/spec": "^1.0.0",
"fast-check": "^3.23.1"
}
}
30 changes: 30 additions & 0 deletions packages/effect/src/Array.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1280,6 +1280,36 @@ export const remove: {
return out
})

/**
* Delete the element at the specified index, creating a new `Array`,
* or return `None` if the index is out of bounds.
*
* @example
* ```ts
* import { Array, Option } from "effect"
*
* const numbers = [1, 2, 3, 4]
* const result = Array.removeOption(numbers, 2)
* assert.deepStrictEqual(result, Option.some([1, 2, 4]))
*
* const outOfBoundsResult = Array.removeOption(numbers, 5)
* assert.deepStrictEqual(outOfBoundsResult, Option.none())
* ```
*
* @since 3.13.0
*/
export const removeOption: {
(i: number): <A>(self: Iterable<A>) => Option<Array<A>>
<A>(self: Iterable<A>, i: number): Option<Array<A>>
} = dual(2, <A>(self: Iterable<A>, i: number): Option<Array<A>> => {
const out = Array.from(self)
if (isOutOfBound(i, out)) {
return O.none()
}
out.splice(i, 1)
return O.some(out)
})

/**
* Reverse an `Iterable`, creating a new `Array`.
*
Expand Down
11 changes: 11 additions & 0 deletions packages/effect/src/Chunk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1235,6 +1235,17 @@ export const remove: {
<A>(self: Chunk<A>, i: number): Chunk<A> => unsafeFromArray(RA.remove(toReadonlyArray(self), i))
)

/**
* @since 3.13.0
*/
export const removeOption: {
(i: number): <A>(self: Chunk<A>) => Option<Chunk<A>>
<A>(self: Chunk<A>, i: number): Option<Chunk<A>>
} = dual(
2,
<A>(self: Chunk<A>, i: number): Option<Chunk<A>> => O.map(RA.removeOption(toReadonlyArray(self), i), unsafeFromArray)
)

/**
* @since 2.0.0
*/
Expand Down
17 changes: 17 additions & 0 deletions packages/effect/src/DateTime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,23 @@ export const unsafeNow: LazyArg<Utc> = Internal.unsafeNow
// time zones
// =============================================================================

/**
* For a `DateTime` returns a new `DateTime.Utc`.
*
* @since 3.13.0
* @category time zones
* @example
* ```ts
* import { DateTime } from "effect"
*
* const now = DateTime.unsafeMakeZoned({ year: 2024 }, { timeZone: "Europe/London" })
*
* // set as UTC
* const utc: DateTime.Utc = DateTime.toUtc(now)
* ```
*/
export const toUtc: (self: DateTime) => Utc = Internal.toUtc

/**
* Set the time zone of a `DateTime`, returning a new `DateTime.Zoned`.
*
Expand Down
3 changes: 2 additions & 1 deletion packages/effect/src/Differ.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import * as HashMapPatch from "./internal/differ/hashMapPatch.js"
import * as HashSetPatch from "./internal/differ/hashSetPatch.js"
import * as OrPatch from "./internal/differ/orPatch.js"
import * as ReadonlyArrayPatch from "./internal/differ/readonlyArrayPatch.js"
import type { Pipeable } from "./Pipeable.js"
import type * as Types from "./Types.js"

/**
Expand Down Expand Up @@ -48,7 +49,7 @@ export type TypeId = typeof TypeId
* @since 2.0.0
* @category models
*/
export interface Differ<in out Value, in out Patch> {
export interface Differ<in out Value, in out Patch> extends Pipeable {
readonly [TypeId]: {
readonly _V: Types.Invariant<Value>
readonly _P: Types.Invariant<Patch>
Expand Down
Loading