github Effect-TS/effect effect@3.13.0

latest releases: @effect/sql-libsql@0.20.2, @effect/cluster-workflow@0.25.2, @effect/vitest@0.19.0...
8 days ago

Minor Changes

  • #4280 8baef83 Thanks @tim-smart! - add Promise based apis to Fiber{Handle,Set,Map} modules

  • #4280 655bfe2 Thanks @gcanti! - 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

    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 }
  • #4280 d90cbc2 Thanks @indietyp! - Add Effect.whenLogLevel, which conditionally executes an effect if the specified log level is enabled

  • #4280 75632bd Thanks @tim-smart! - add RcMap.touch, for reseting the idle timeout for an item

  • #4280 c874a2e Thanks @LaureRC! - Add HashMap.some

  • #4280 bf865e5 Thanks @tim-smart! - allow accessing args in Effect.fn pipe

  • #4280 f98b2b7 Thanks @tim-smart! - add RcMap.invalidate api, for removing a resource from an RcMap

  • #4280 de8ce92 Thanks @mikearnaldi! - Add Layer.updateService mirroring Effect.updateService

  • #4280 db426a5 Thanks @KhraksMamtsov! - Differ implements Pipeable

  • #4280 6862444 Thanks @thewilkybarkid! - Make it easy to convert a DateTime.Zoned to a DateTime.Utc

  • #4280 5fc8a90 Thanks @gcanti! - Add missing Either.void constructor.

  • #4280 546a492 Thanks @vinassefranche! - Add HashMap.toValues and HashSet.toValues getters

  • #4280 65c4796 Thanks @tim-smart! - add {FiberHandle,FiberSet,FiberMap}.awaitEmpty apis

  • #4280 9760fdc Thanks @gcanti! - Schema: Add standardSchemaV1 API to Generate a Standard Schema v1.

    Example

    import { Schema } from "effect"
    
    const schema = Schema.Struct({
      name: Schema.String
    })
    
    //      ┌─── StandardSchemaV1<{ readonly name: string; }>
    //      ▼
    const standardSchema = Schema.standardSchemaV1(schema)
  • #4280 5b471e7 Thanks @fubhy! - Added Duration.formatIso and Duration.fromIso for formatting and parsing ISO8601 durations.

  • #4280 4f810cc Thanks @tim-smart! - add Effect.filterEffect* apis

    Effect.filterEffectOrElse

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

    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.

    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}`))
      })
    )

Patch Changes

  • #4280 cf8b2dd Thanks @KhraksMamtsov! - Trie<out A> type annotations have been aligned. The type parameter was made covariant because the structure is immutable.

Don't miss a new effect release

NewReleases is sending notifications on new releases.