Skip to content

Methrat0n/IfMonad

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

IfMonad

The If Monad allows easier composition of conditions and helps build more complex expressions. It may help when validating data, if you need to test your values over multiple rules.

val director = "Steven Spielberg"
for {
  themes <- 
    If(director.contains(" "),
      themeQuery.getByDirectorFullName(director), 
    Else(
      nameQuery.getByDirectorSimpleName(director)
    ))
  bestMovie <- 
    If(themes.contains("Sci Fi"),
      SciFiQuery.takeFirstFromDirector(director),
    Else(
      MovieQuery.takeOneByTheme(themes.head)
    ))
} yield bestMovie 

This same selection could have been done using Either or Option but is clearer in this form. Later, if we want to return to our usual Monads, we can use the toEither helper.

About

Home of the IfMonad

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages