diff options
author | Jon Pretty <jon.pretty@propensive.com> | 2017-06-11 16:56:44 +0200 |
---|---|---|
committer | Jon Pretty <jon.pretty@propensive.com> | 2017-06-11 16:56:44 +0200 |
commit | 9ff2305bcdd742529bd184ba90ecdef32ca2fe4d (patch) | |
tree | 26e6df52df42eb3ac4206c198ee97c2ea0c11053 /examples | |
parent | f22b602f0180500e45db76ec20f6bfd3f2450842 (diff) | |
download | magnolia-9ff2305bcdd742529bd184ba90ecdef32ca2fe4d.tar.gz magnolia-9ff2305bcdd742529bd184ba90ecdef32ca2fe4d.tar.bz2 magnolia-9ff2305bcdd742529bd184ba90ecdef32ca2fe4d.zip |
Generalized for typeclass-based extension
Diffstat (limited to 'examples')
-rw-r--r-- | examples/src/main/scala/example.scala | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/examples/src/main/scala/example.scala b/examples/src/main/scala/example.scala index 6a6a1cc..e61f8bd 100644 --- a/examples/src/main/scala/example.scala +++ b/examples/src/main/scala/example.scala @@ -34,6 +34,12 @@ object Extractor extends Extractor_1 { type Value = Thing def dereference(value: Thing, param: String): Thing = value.access(param) def delegate[T](extractor: Extractor[T], value: Thing): T = extractor.extract(value) + def combine[Supertype, Right <: Supertype](left: Extractor[_ <: Supertype], + right: Extractor[Right]): Extractor[Supertype] = left.orElse(right) + + def construct[T](body: Thing => T): Extractor[T] = new Extractor[T] { + def extract(source: Thing): T = body(source) + } } } |