Skip to content
This repository has been archived by the owner on Aug 19, 2020. It is now read-only.

Commit

Permalink
Merge pull request #1194 from JLLeitschuh/callable-extensions
Browse files Browse the repository at this point in the history
Add invoke operator to Callable
  • Loading branch information
eskatos authored Oct 19, 2018
2 parents 621d00f + b9fe5ea commit d65d569
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Copyright 2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.gradle.kotlin.dsl

import java.util.concurrent.Callable


/**
* Enables function invocation syntax on [Callable] references.
* @see Callable.call
*/
operator fun <V> Callable<V>.invoke(): V =
call()
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Copyright 2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.gradle.kotlin.dsl

import org.junit.Assert.assertEquals
import org.junit.Test
import java.util.concurrent.Callable


class CallableExtensionsTest {

@Test
fun `Callable#call can be called using invoke`() {
val answer = "42"
val answerCallable = Callable { answer }

assertEquals(answer, answerCallable())
}
}

0 comments on commit d65d569

Please sign in to comment.