Created
April 27, 2012 20:41
-
-
Save aztek/2512901 to your computer and use it in GitHub Desktop.
Scala functions defined in JavaBeans
This file contains hidden or 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
<?xml version="1.0" encoding="utf-8"?> | |
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd"> | |
<beans default-lazy-init="true" default-autowire="byName"> | |
<bean id="increment" class="com.myapp.IntegerFunctions" factory-method="increment" /> | |
<bean id="decrement" class="com.myapp.IntegerFunctions" factory-method="decrement" /> | |
<bean id="appendBangs" class="com.myapp.IntegerFunctions" factory-method="lolNoIntegers" /> | |
<bean id="doubleIncrement" class="com.myapp.IntegersFunctionDoubleApplication"> | |
<property name="function" ref="increment"/> | |
</bean> | |
<bean id="doubleDecrement" class="com.myapp.IntegersFunctionDoubleApplication"> | |
<property name="function" ref="decrement"/> | |
</bean> | |
<!-- Will pass validation but cause runtime error due to type erasure :( --> | |
<bean id="someShit" class="com.myapp.IntegersFunctionDoubleApplication"> | |
<property name="function" ref="appendBangs"/> | |
</bean> | |
</beans> |
This file contains hidden or 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
package com.myapp | |
object IntegerFunctions { | |
val increment: Int => Int = _ + 1 | |
val decrement: Int => Int = _ + 1 | |
val lolNoIntegers: String => String = _ + "!!!" | |
} |
This file contains hidden or 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
package com.myapp | |
import reflect.BeanProperty | |
import org.springframework.beans.factory.annotation.Required | |
class IntegersFunctionDoubleApplication { | |
@BeanProperty | |
@Required | |
var function: Int => Int = _ | |
def applyTwice = function andThen function | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment