Skip to content

Commit

Permalink
use gleam 1.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
bwireman committed Apr 16, 2024
1 parent 2023477 commit 1d72418
Show file tree
Hide file tree
Showing 12 changed files with 653 additions and 602 deletions.
2 changes: 1 addition & 1 deletion .tool-versions
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
gleam 1.0.0
gleam 1.1.0
erlang 26.2.2
nodejs 21.6.1
44 changes: 22 additions & 22 deletions dist/delay.d.mts
Original file line number Diff line number Diff line change
Expand Up @@ -2,65 +2,65 @@
/**
* Type representing a delayed effect to be lazily evaluated
*/
export type Delay$<FXE, FXD> = Continue<FXE, FXD> | Stop<FXE>
export type Delay$<GCD, GCE> = Continue<GCD, GCE> | Stop<GCE>


/**
* Stores an effect to be run later, short circuiting on errors
*/
export function delay_effect<FXF, FXG>(func: () => Result<FXF, FXG>): Delay$<FXF, FXG>
export function delay_effect<GCF, GCG>(func: () => Result<GCF, GCG>): Delay$<GCF, GCG>


/**
* Chains an operation onto an existing delay. The result of the current delay will be lazily passed to `func`
* `func` will not be called if the delay has already returned an error
*/
export function map<FXL, FXM, FXP>(delayed: Delay$<FXL, FXM>, func: (x0: FXL) => Result<FXP, FXM>): Delay$<FXP, FXM>
export function map<GCL, GCM, GCP>(delayed: Delay$<GCL, GCM>, func: (x0: GCL) => Result<GCP, GCM>): Delay$<GCP, GCM>


/**
* flatten a nested Delay
*/
export function flatten<FYD, FYE>(delayed: Delay$<Delay$<FYD, FYE>, FYE>): Delay$<FYD, FYE>
export function flatten<GDD, GDE>(delayed: Delay$<Delay$<GDD, GDE>, GDE>): Delay$<GDD, GDE>


/**
* Map and then flatten `delayed`
*/
export function flat_map<FYL, FYM, FYP>(
delayed: Delay$<FYL, FYM>,
func: (x0: FYL) => Result<Delay$<FYP, FYM>, FYM>
): Delay$<FYP, FYM>
export function flat_map<GDL, GDM, GDP>(
delayed: Delay$<GDL, GDM>,
func: (x0: GDL) => Result<Delay$<GDP, GDM>, GDM>
): Delay$<GDP, GDM>


/**
* Run a delayed effect and get the result
* short-circuiting if any in delay in the chain returns an Error
*/
export function run<GAA, GAB>(delayed: Delay$<GAA, GAB>): Result<GAA, GAB>
export function run<GFA, GFB>(delayed: Delay$<GFA, GFB>): Result<GFA, GFB>


/**
* returns a delay, that joins two delays. If `left` fails `right` will not be run, if either fails the result will be an Error
*/
export function join<FYW, FYX, FZA, FZB>(
left: Delay$<FYW, FYX>,
right: Delay$<FZA, FZB>
): Delay$<[FYW, FZA], [Option$<FYX>, Option$<FZB>]>
export function join<GDW, GDX, GEA, GEB>(
left: Delay$<GDW, GDX>,
right: Delay$<GEA, GEB>
): Delay$<[GDW, GEA], [Option$<GDX>, Option$<GEB>]>


/**
* Returns a new Delay that will be re-attempted `retries` times with `delay` ms in-between
* NOTE: `delay` is ignored in JS
*/
export function retry<FZI, FZJ>(delayed: Delay$<FZI, FZJ>, retries: number, delay: number): Delay$<FZI, FZJ>
export function retry<GEI, GEJ>(delayed: Delay$<GEI, GEJ>, retries: number, delay: number): Delay$<GEI, GEJ>


/**
* Returns a new Delay that will be re-attempted `retries` times with `delay` ms in-between
* NOTE: `delay` is ignored in JS
*/
export function retry_with_backoff<FZO, FZP>(delayed: Delay$<FZO, FZP>, retries: number): Delay$<FZO, FZP>
export function retry_with_backoff<GEO, GEP>(delayed: Delay$<GEO, GEP>, retries: number): Delay$<GEO, GEP>


/**
Expand All @@ -73,13 +73,13 @@ export function drain(delayed: Delay$<any, any>): null
/**
* Run every effect in sequence and get their results
*/
export function every<GAR, GAS>(effects: List<Delay$<GAR, GAS>>): List<Result<GAR, GAS>>
export function every<GFR, GFS>(effects: List<Delay$<GFR, GFS>>): List<Result<GFR, GFS>>


/**
* Repeat a Delay and return the results in a list
*/
export function repeat<GAK, GAL>(delayed: Delay$<GAK, GAL>, repetition: number): List<Result<GAK, GAL>>
export function repeat<GFK, GFL>(delayed: Delay$<GFK, GFL>, repetition: number): List<Result<GFK, GFL>>


/**
Expand All @@ -100,16 +100,16 @@ export function any(effects: List<Delay$<any, any>>): boolean
* Attempt multiple Delays until one returns an Ok
* unlike `any/1` this will short circuit on the first Ok
*/
export function fallthrough<GBU, GBV>(effects: List<Delay$<GBU, GBV>>): Result<GBU, GBV>
export function fallthrough<GGU, GGV>(effects: List<Delay$<GGU, GGV>>): Result<GGU, GGV>

export class Continue<FXD, FXE> extends CustomType {
export class Continue<GCE, GCD> extends CustomType {
constructor(effect: () => Result<any, any>)
effect(): Result<any, any>
}

export class Stop<FXE> extends CustomType {
constructor(err: FXE)
err: FXE
export class Stop<GCE> extends CustomType {
constructor(err: GCE)
err: GCE
}

export class Result<T, E> extends CustomType {
Expand Down
19 changes: 10 additions & 9 deletions dist/delay.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
var __defProp = Object.defineProperty
var __name = (target, value) => __defProp(target, "name", { value, configurable: true })

import { Ok as Ok7, Error as Error9, toList as toList7 } from "./extras/prelude.mjs"
import { Ok as Ok7, Error as Error9, toList as toList7, prepend as listPrepend6 } from "./extras/prelude.mjs"

import { CustomType as $CustomType } from "./extras/prelude.mjs"
var Some = class extends $CustomType {
Expand Down Expand Up @@ -88,7 +88,7 @@ function do_reverse_acc(loop$remaining, loop$accumulator) {
let item = remaining.head
let rest$1 = remaining.tail
loop$remaining = rest$1
loop$accumulator = toList7([item], accumulator)
loop$accumulator = listPrepend6(item, accumulator)
}
}
}
Expand All @@ -114,7 +114,7 @@ function do_filter(loop$list, loop$fun, loop$acc) {
let new_acc = (() => {
let $ = fun(x)
if ($) {
return toList7([x], acc)
return listPrepend6(x, acc)
} else {
return acc
}
Expand Down Expand Up @@ -145,7 +145,7 @@ function do_try_map(loop$list, loop$fun, loop$acc) {
let y = $[0]
loop$list = xs
loop$fun = fun
loop$acc = toList7([y], acc)
loop$acc = listPrepend6(y, acc)
} else {
let error = $[0]
return new Error9(error)
Expand All @@ -169,7 +169,7 @@ function do_repeat(loop$a, loop$times, loop$acc) {
} else {
loop$a = a
loop$times = times - 1
loop$acc = toList7([a], acc)
loop$acc = listPrepend6(a, acc)
}
}
}
Expand All @@ -184,6 +184,7 @@ import {
Ok as Ok8,
Error as Error10,
toList as toList8,
prepend as listPrepend7,
CustomType as $CustomType7,
makeError
} from "./extras/prelude.mjs"
Expand Down Expand Up @@ -382,14 +383,14 @@ function do_every(loop$effects, loop$results) {
let results = loop$results
if (effects.hasLength(1)) {
let last = effects.head
return toList8([run(last)], results)
return listPrepend7(run(last), results)
} else if (effects.atLeastLength(1)) {
let head = effects.head
let rest = effects.tail
loop$effects = rest
loop$results = toList8([run(head)], results)
loop$results = listPrepend7(run(head), results)

Check warning on line 391 in dist/delay.mjs

View workflow job for this annotation

GitHub Actions / test

'$' is assigned a value but never used. Allowed unused vars must match /^_/u
} else {
throw makeError("todo", "delay", 198, "do_every", "Empty list", {})
throw makeError("panic", "delay", 198, "do_every", "Empty list", {})
}
}
}
Expand Down Expand Up @@ -451,7 +452,7 @@ function do_fallthrough(effects) {
return fallthrough(rest)
})
} else {
throw makeError("todo", "delay", 213, "do_fallthrough", "Empty list", {})
throw makeError("panic", "delay", 213, "do_fallthrough", "Empty list", {})
}
}
__name(do_fallthrough, "do_fallthrough")
Expand Down

0 comments on commit 1d72418

Please sign in to comment.