Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Aug 27, 2024. It is now read-only.

Non-Deterministic effects in Scala

License

NotificationsYou must be signed in to change notification settings

MateuszKubuszok/nondeterministic

Repository files navigation

A PoC of non-deterministic effects (assumes effect is referentially transparent is sth).

(Not tested, just a draft)

Idea

// these are deterministic effectsdefcreateUser(newUser:CreateUser):F[User]deflogout(user:User):F[Unit]defcheckSomePage(user:User):F[Page]// this makes effects non-deterministic// we can combine 2 branches and only one of them will be followeddefndLogout(user:User):NonDeterministicT[F,Unit]=NonDeterministicT.liftF(logout(user))defndCheckPage(user:User):NonDeterministicT[F,Unit]=>NonDeterministicT.liftF(checkSomePage(user))defndUserBehavior(user:User):NonDeterministicT[F,Unit]=// The first path will have its likelihood increased 9 times,// the second path will have its original weight (1),// which should result in branch picking the first branch 9 times out of 9+1=10,// and the second branch 1 time out of 10.  ndCheckPage(user).flatMap(_=> ndUserBehavior(user)).scale(9)<+> ndLogout(user)// this should create user and then randomly decide between// checking page and logging out - once logged out, it should finishNonDeterministicT.liftF(createUser(newUser))// NonDeterministicT[F, User]  .flatMap(ndUserBehavior)// NonDeterministicT[F, Unit]  .execute(Decider.random())// F[Unit]

About

Non-Deterministic effects in Scala

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp