This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export function range(count: number, start = 0, step = 1): Stream<number> { | |
return (snk) => { | |
let open = true; | |
let index = Math.floor(Math.max(0, count)); | |
let value = start; | |
let readyCount = 0; | |
let pulling = false; | |
const close = () => open = false; | |
const talk = snk((count) => { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import type { $, In, InOut, Kind, Out } from "../kind.ts"; | |
import type { Option } from "../option.ts"; | |
import type { Flatmappable } from "../flatmappable.ts"; | |
import type { Fn } from "../fn.ts"; | |
import * as F from "../fn.ts"; | |
import { createBind, createTap } from "../flatmappable.ts"; | |
import { createBindTo } from "../mappable.ts"; | |
import { pipe } from "../fn.ts"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Here are some ideas for router and route. Handler is already set as an async | |
* indexed state monad. | |
* | |
* ```ts | |
* export type Handler<D, A, B> = (d: D) => Promise<[A, B]>; | |
* ``` | |
*/ | |
import type { Option } from "fun/option.ts"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** @jsx h */ | |
import { pipe } from "fun/fn.ts"; | |
import { h } from "https://esm.sh/[email protected]"; | |
import * as R from "../router.ts"; | |
import { jsx } from "../jsx.ts"; | |
type State = { count: number }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const apply1 = | |
<A>(ua: Promise<A>) => <I>(ufai: Promise<(a: A) => I>): Promise<I> => | |
Promise.all([ua, ufai]).then(([a, fai]) => fai(a)); | |
export const apply2: <A>( | |
ua: Promise<A>, | |
) => <I>(ufai: Promise<(a: A) => I>) => Promise<I> = apply1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import type { $, Kind } from "https://deno.land/x/fun/kind.ts"; | |
import type { Applicative } from "https://deno.land/x/fun/applicative.ts"; | |
import { pipe } from "https://deno.land/x/fun/fn.ts"; | |
export function curry2<A, B, C>(f: (a: A, b: B) => C): (a: A) => (b: B) => C { | |
return (a) => (b) => f(a, b); | |
} | |
export function curry3<A, B, C, D>( |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cpu: Apple M1 Max | |
runtime: deno 1.29.1 (aarch64-apple-darwin) | |
file:///Users/brandon/src/fun/main/benchmarks/fn.bench.ts | |
benchmark time (avg) (min … max) p75 p99 p995 | |
------------------------------------------------------------- ----------------------------- | |
flowOptimized 262.67 ns/iter (251.3 ns … 443.08 ns) 259.91 ns 312.58 ns 341.9 ns | |
flowReduceConst 404.92 ns/iter (395.69 ns … 504.78 ns) 402.08 ns 504.4 ns 504.78 ns | |
flowReduceFunction 510.3 ns/iter (504.26 ns … 540.63 ns) 510.64 ns 539.74 ns 540.63 ns |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// deno-lint-ignore-file no-explicit-any | |
/** | |
* I think this is a stack safe implementation of Fn/Reader.. | |
* | |
* I haven't really tested it though.. | |
* | |
* The core idea here is to build up an array of "Controls" | |
* that represent a few core operations over a LazyFn. To | |
* keep things simple we only implement controls for id, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import type { Either } from "fun/either.ts"; | |
import type { Option } from "fun/option.ts"; | |
import type { Hold } from "fun/kind.ts"; | |
import * as A from "fun/array.ts"; | |
import * as E from "fun/either.ts"; | |
import * as O from "fun/option.ts"; | |
import { flow, pipe, todo } from "fun/fn.ts"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* See | |
* * https://okmij.org/ftp/Computation/free-monad.html | |
* * https://github.com/gcanti/fp-ts-contrib/blob/master/src/Free.ts | |
* * https://reasonablypolymorphic.com/blog/freer-monads/ | |
* * https://serokell.io/blog/introduction-to-free-monads | |
*/ | |
import { flow, identity, pipe, todo } from "https://deno.land/x/fun/fn.ts"; |
NewerOlder