Skip to content

koterpillar/foreshadowing

Repository files navigation

Foreshadowing

Learn something about your values before they are computed!

import com.koterpillar.foreshadowing._

val isVowel = Set('a', 'e', 'i', 'o', 'u')

val Eventually(res) = for {
  len <- Divination[String, Int](_.length)
  vowels <- Divination[String, Int](_.count(isVowel))
} yield s"This string has $len characters. Of those, $vowels are vowels."

// res: String = This string has 55 characters. Of those, 12 are vowels.

res.length
// 55

res.count(isVowel)
// 12

Limitations

Divination power is not very strong yet. Asking for the impossible will lead one onto the infinite road through time and space @tailrec fixed the space bit.

Scala cannot divine up enough types, somewhat breaking the immersion.

Motivation

This is indirectly inspired by a colleauge mentioning that for comprehensions are sequencing the computation. Of course they do... normally.

Also see:

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages