Skip to content

Instantly share code, notes, and snippets.

@catb0t
Forked from jemc/sylvan-auth-gist.pony
Created January 17, 2022 18:41
Show Gist options
  • Save catb0t/0905fa263d72fd9dbd10d194d52d41da to your computer and use it in GitHub Desktop.
Save catb0t/0905fa263d72fd9dbd10d194d52d41da 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