midas/effect

The effect module defines all the side effects supported by Midas. It also defines functions to compose effectful functions

Gleam does not offer extensible types and so adding new types will require contribution to this project.

Use this module to explicitly handle errors, use the midas/task module for a simpler API where all errors are snag errors.

Types

pub type Effect(a, key) {
  Done(a)
  Bundle(
    module: String,
    function: String,
    resume: fn(Result(String, String)) -> Effect(a, key),
  )
  ExportJsonWebKey(
    key: key,
    resume: fn(Result(json.Json, String)) -> Effect(a, key),
  )
  Follow(
    uri: uri.Uri,
    resume: fn(Result(uri.Uri, Nil)) -> Effect(a, key),
  )
  Fetch(
    request: request.Request(BitArray),
    resume: fn(Result(response.Response(BitArray), FetchError)) -> Effect(
      a,
      key,
    ),
  )
  GenerateKeyPair(
    algorithm: KeyPairAlgorithm,
    extractable: Bool,
    usages: List(KeyUsage),
    resume: fn(Result(KeyPair(key), String)) -> Effect(a, key),
  )
  Hash(
    algorithm: HashAlgorithm,
    bytes: BitArray,
    resume: fn(Result(BitArray, String)) -> Effect(a, key),
  )
  List(
    directory: String,
    resume: fn(Result(List(String), String)) -> Effect(a, key),
  )
  Log(
    message: String,
    resume: fn(Result(Nil, Nil)) -> Effect(a, key),
  )
  Read(
    file: String,
    resume: fn(Result(BitArray, String)) -> Effect(a, key),
  )
  Serve(
    port: option.Option(Int),
    handle: fn(request.Request(BitArray)) -> response.Response(
      BitArray,
    ),
    resume: fn(Result(Nil, String)) -> Effect(a, key),
  )
  Sign(
    algorithm: SignAlgorithm,
    key: key,
    data: BitArray,
    resume: fn(Result(BitArray, String)) -> Effect(a, key),
  )
  StrongRandom(
    length: Int,
    resume: fn(Result(BitArray, String)) -> Effect(a, key),
  )
  Write(
    file: String,
    bytes: BitArray,
    resume: fn(Result(Nil, String)) -> Effect(a, key),
  )
  Visit(
    uri: uri.Uri,
    resume: fn(Result(Nil, String)) -> Effect(a, key),
  )
  Zip(
    files: List(#(String, BitArray)),
    resume: fn(Result(BitArray, Nil)) -> Effect(a, key),
  )
  UnixNow(resume: fn(Int) -> Effect(a, key))
}

Constructors

  • Done(a)
  • Bundle(
      module: String,
      function: String,
      resume: fn(Result(String, String)) -> Effect(a, key),
    )
  • ExportJsonWebKey(
      key: key,
      resume: fn(Result(json.Json, String)) -> Effect(a, key),
    )
  • Follow(
      uri: uri.Uri,
      resume: fn(Result(uri.Uri, Nil)) -> Effect(a, key),
    )
  • Fetch(
      request: request.Request(BitArray),
      resume: fn(Result(response.Response(BitArray), FetchError)) -> Effect(
        a,
        key,
      ),
    )
  • GenerateKeyPair(
      algorithm: KeyPairAlgorithm,
      extractable: Bool,
      usages: List(KeyUsage),
      resume: fn(Result(KeyPair(key), String)) -> Effect(a, key),
    )
  • Hash(
      algorithm: HashAlgorithm,
      bytes: BitArray,
      resume: fn(Result(BitArray, String)) -> Effect(a, key),
    )
  • List(
      directory: String,
      resume: fn(Result(List(String), String)) -> Effect(a, key),
    )
  • Log(
      message: String,
      resume: fn(Result(Nil, Nil)) -> Effect(a, key),
    )
  • Read(
      file: String,
      resume: fn(Result(BitArray, String)) -> Effect(a, key),
    )
  • Serve(
      port: option.Option(Int),
      handle: fn(request.Request(BitArray)) -> response.Response(
        BitArray,
      ),
      resume: fn(Result(Nil, String)) -> Effect(a, key),
    )
  • Sign(
      algorithm: SignAlgorithm,
      key: key,
      data: BitArray,
      resume: fn(Result(BitArray, String)) -> Effect(a, key),
    )
  • StrongRandom(
      length: Int,
      resume: fn(Result(BitArray, String)) -> Effect(a, key),
    )
  • Write(
      file: String,
      bytes: BitArray,
      resume: fn(Result(Nil, String)) -> Effect(a, key),
    )
  • Visit(
      uri: uri.Uri,
      resume: fn(Result(Nil, String)) -> Effect(a, key),
    )
  • Zip(
      files: List(#(String, BitArray)),
      resume: fn(Result(BitArray, Nil)) -> Effect(a, key),
    )
  • UnixNow(resume: fn(Int) -> Effect(a, key))
pub type FetchError {
  NetworkError(String)
  UnableToReadBody
  NotImplemented
}

Constructors

  • NetworkError(String)
  • UnableToReadBody
  • NotImplemented
pub type HashAlgorithm {
  Sha1
  Sha256
  Sha384
  Sha512
}

Constructors

  • Sha1
  • Sha256
  • Sha384
  • Sha512
pub type KeyPair(key) {
  KeyPair(public: key, private: key)
}

Constructors

  • KeyPair(public: key, private: key)
pub type KeyPairAlgorithm {
  EcKeyGenParams(name: String, named_curve: String)
}

Constructors

  • EcKeyGenParams(name: String, named_curve: String)
pub type KeyUsage {
  CanEncrypt
  CanDecrypt
  CanSign
  CanVerify
  CanDeriveKey
  CanDeriveBits
  CanWrapKey
  CanUnwrapKey
}

Constructors

  • CanEncrypt
  • CanDecrypt
  • CanSign
  • CanVerify
  • CanDeriveKey
  • CanDeriveBits
  • CanWrapKey
  • CanUnwrapKey
pub type SignAlgorithm {
  EcdsaParams(hash: HashAlgorithm)
}

Constructors

Values

pub fn bundle(
  module: String,
  function: String,
) -> Effect(Result(String, String), a)
pub fn do(
  eff: Effect(a, b),
  next: fn(a) -> Effect(c, b),
) -> Effect(c, b)
pub fn each(
  items: List(a),
  run: fn(a) -> Effect(b, c),
) -> Effect(List(b), c)
pub fn export_jwk(key: a) -> Effect(Result(json.Json, String), a)
pub fn fetch(
  request: request.Request(BitArray),
) -> Effect(Result(response.Response(BitArray), FetchError), a)
pub fn follow(uri: uri.Uri) -> Effect(Result(uri.Uri, Nil), a)
pub fn generate_keypair(
  algorithm: KeyPairAlgorithm,
  extractable: Bool,
  usages: List(KeyUsage),
) -> Effect(Result(KeyPair(a), String), a)
pub fn hash(
  algorithm: HashAlgorithm,
  bytes: BitArray,
) -> Effect(Result(BitArray, String), a)
pub fn list(
  directory: String,
) -> Effect(Result(List(String), String), a)
pub fn log(message: String) -> Effect(Result(Nil, Nil), a)
pub fn proxy(
  task: Effect(a, b),
  scheme: http.Scheme,
  host: String,
  port: option.Option(Int),
  prefix: String,
) -> Effect(a, b)
pub fn read(file: String) -> Effect(Result(BitArray, String), a)
pub fn sequential(
  tasks: List(Effect(a, b)),
) -> Effect(List(a), b)
pub fn serve(
  port: option.Option(Int),
  handle: fn(request.Request(BitArray)) -> response.Response(
    BitArray,
  ),
) -> Effect(Result(Nil, String), a)
pub fn serve_static(
  port: option.Option(Int),
  files: List(#(String, BitArray)),
) -> Effect(Result(Nil, String), a)
pub fn sign(
  algorithm: SignAlgorithm,
  key: a,
  data: BitArray,
) -> Effect(Result(BitArray, String), a)
pub fn strong_random(
  length: Int,
) -> Effect(Result(BitArray, String), a)
pub fn unix_now() -> Effect(Int, a)
pub fn visit(uri: uri.Uri) -> Effect(Result(Nil, String), a)
pub fn write(
  file: String,
  bytes: BitArray,
) -> Effect(Result(Nil, String), a)
pub fn zip(
  files: List(#(String, BitArray)),
) -> Effect(Result(BitArray, Nil), a)
Search Document