Skip to content

Instantly share code, notes, and snippets.

@jemc
Created January 11, 2022 20:01
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jemc/94e80a1173fa91a80f822988b5c32b7f to your computer and use it in GitHub Desktop.
Save jemc/94e80a1173fa91a80f822988b5c32b7f to your computer and use it in GitHub Desktop.
interface val Auth
fun val apply[B: Auth val](): B ? =>
this as B
fun val add(that: Auth): AuthSet =>
AuthSet(this, that)
class val AuthSet is Auth
let _a: Auth
let _b: Auth
new val create(a: Auth, b: Auth) =>
_a = a
_b = b
fun val apply[B: Auth val](): B ? =>
try
_a[B]()?
else
_b[B]()?
end
primitive AmbientAuth2 is Auth
new create(auth: AmbientAuth) => None
primitive FooAuth is Auth
new create(auth: AmbientAuth2) => None
primitive BarAuth is Auth
new create(auth: AmbientAuth2) => None
primitive Foo2Auth is Auth
new create(auth: FooAuth) => None
primitive Bar2Auth is Auth
new create(auth: BarAuth) => None
primitive FooBar2Auth is Auth
new create(auth1: FooAuth, auth2: BarAuth) => None
actor Main
new create(env: Env) =>
try
let auth = AmbientAuth2(env.root as AmbientAuth)
let foo = FooAuth(auth)
let bar = BarAuth(auth)
let both = foo + bar
let foo2 = Foo2Auth(both[FooAuth]()?)
let bar2 = Bar2Auth(both[BarAuth]()?)
let both2 = FooBar2Auth(both[FooAuth]()?, both[BarAuth]()?)
env.out.print("ok")
else
env.out.print("not ok")
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment