Created
January 12, 2013 18:19
-
-
Save mdekstrand/4519727 to your computer and use it in GitHub Desktop.
Code for path-dependent type post.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
trait InfoNeed { | |
type DataType | |
/** Get the web request to fetch data */ | |
def request: WebRequest[DataType] | |
/** Get the neighbors from some fetched data (to determine new nodes to visit) */ | |
def neighbors(data: DataType): Traversable[Node] | |
/** Save the data to the data store. */ | |
def save(store: DataStore, data: DataType) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def fetch[T](req: WebRequest[T]): Result[T] | |
def process(need: Need) { | |
val req = need.request | |
val res = fetch(req) | |
// now we save the data | |
res match { | |
case Good(data) => need.save(store, data) | |
/* error cases */ | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment