Repository navigation
0.8.0
Features
By popular request: this is the first release shipping an adapter for commonly used Web APIs, namely fetch.
liftFetch().: Liftsfetch-like functions into aTaskcontext. This comes with "sane" defaults for the construction of the possible error paths and is flexible enough to accomodate a variety of validation needs.
import { liftFetch } from "https://deno.land/x/eitherway@0.10.0/mod.ts";
interface Company {
name: string;
}
interface User {
id: number;
company: Company;
}
interface UserResponse extends Response {
json(): Promise<User>
}
function fetchUserById(id: number): Promise<UserResponse> {
return fetch(`https://jsonplaceholder.typicode.com/users/${id}`);
}
const getUserById = liftFetch(fetchUserById);
const result: Company = await getUserById(1)
.map((resp) => resp.json()) // inferred as User
.inspect(console.log)
.inspectErr(console.error) // FailedRequest<UserResponse> | FetchException
.mapOr(user => user.company, { name: "Acme Corp." })
.unwrap();Full Changelog: 0.7.0...0.8.0