Skip to content

Latest commit

 

History

History
46 lines (32 loc) · 1.32 KB

03_pair.adoc

File metadata and controls

46 lines (32 loc) · 1.32 KB

Extensions to Pair

The class de.fhg.fokus.xtensions.pair.PairExtensions provides extension methods for the type org.eclipse.xtext.xbase.lib.Pair.

The with-operator can be used to destructure a Pair into key and value and returns the input Pair.

Example:

import static extension de.fhg.fokus.xtensions.pair.PairExtensions.*
// ...
val pair = "Foo" -> 3
pair => [k,v|
	println(k + ' -> ' + v)
]

The combine extension method takes a function to which key and value of a Pair is passed to, to merge both objects. The result returned by the function will be returned by the combine method. The difference to the >>> operator, provided by the Extensions to Functions is only that due to operator precedence calling further methods on the result needs further braces.

Example:

import static extension de.fhg.fokus.xtensions.pair.PairExtensions.*
// ...
val pair = "Foo" -> 3
val s = pair.combine[k,v| k + ' = ' + v].toLowerCase
println(s)
Tip

Related JavaDocs: