Skip to content

Instantly share code, notes, and snippets.

View arthurgubaidullin's full-sized avatar

Artur Gubaidullin arthurgubaidullin

View GitHub Profile
@arthurgubaidullin
arthurgubaidullin / using-either-type.ts
Created April 18, 2023 15:01
An example of using the Either type
import * as E from 'fp-ts/Either';
// 1.
const MY_VAR_UNSAFE: string | undefined = process.env['MY_VAR'];
const MY_VAR_NOT_DEFINED = 'Environment variable MY_VAR not set.' as const;
const MY_VAR_EITHER: E.Either<typeof MY_VAR_NOT_DEFINED, string> =
MY_VAR_UNSAFE !== undefined
type person = Streamer(string) | Mr(string)
let kirJs = Streamer("KirJS")
let mrLapteuh = Mr("Lapteuh")
let say = person =>
switch person {
| Streamer(name) => name ++ ": " ++ "Yes, mr. Lapteuh." ++ "\n"
| Mr(name) => "Mr. " ++ name ++ ": " ++ "Say my name!" ++ "\n"
interface InternalEventBrand {
readonly Internal: unique symbol;
}
type User = {}
type AuthorizedEvent = { type: 'AUTHORIZED'; user: User } & InternalEventBrand;
function authorized(user: User): AuthorizedEvent {
return { type: 'AUTHORIZED', user } as AuthorizedEvent;
@arthurgubaidullin
arthurgubaidullin / machine.js
Last active March 23, 2021 12:54
Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions