Commit 29a067ca authored by Günter Hipler's avatar Günter Hipler
Browse files

first quick examples functions in scala

parent 47732501
Pipeline #23741 passed with stages
in 6 minutes and 36 seconds
//identifier: Signatur des Typs = Implementierung des Typs (der Wert der Funtion)
val quadrat: Int => Int = parameter => parameter * parameter
val wertDesQuadratsMitParameter3 = quadrat(3)
//wertDesQuadratsMitParameter3 == 9
//was häufig als syntactic sugar bezeichnet wird
val conciseVerdoppelung: Int => Int = _ * 2
//anstelle von
val conciseVerdoppelung1: Int => Int = input => input * 2
//Type Inferenz (Weglassen der Signatur einer Funktion, wird vom Compiler ermittelt)
val summe = (summand1:Int, summand2: Int) => summand1 + summand2
//Currying - wird viel in den Extractors verwendet
val curriedFunctionSumme: Int => Int => Int = par1 => par2 => par1 + par2
curriedFunctionSumme(3)(4) // == 7
//am konkreten Beispiel
import ujson.Value.{Value => JValue}
import ujson.{Arr => JArr, Obj => JObj, Str => JStr}
import scala.collection.mutable
import scala.collection.mutable.ArrayBuffer
import scala.util.Try
import ch.memobase.rico2edm.edm.Extractors
val testGraph =
"""
|{
| "@graph": [
| {
| "@id": "_:b0",
| "@type": "https://www.ica.org/standards/RiC/ontology#Identifier",
| "identifier": "ati-002-22861-1",
| "type": "main"
| },
| {
| "@id": "_:b1",
| "@type": "http://www.w3.org/2004/02/skos/core#Concept",
| "prefLabel": "Guerra civile in Spagna"
| },
| {
| "@id": "https://memobase.ch/digital/ati-002-22861-1",
| "@type": "https://www.ica.org/standards/RiC/ontology#Instantiation",
| "eventType": "CREATE",
| "identifiedBy": "_:b15",
| "instantiates": "https://memobase.ch/record/ati-002-22861",
| "isDerivedFromInstantiation": "https://memobase.ch/physical/ati-002-22861-1",
| "regulatedBy": [
| "_:b13",
| "_:b16"
| ],
| "type": "digitalObject"
| }
| ]
| }
|""".stripMargin
Extractors
//function liefert den kompletten Graph zurück
.jsonGraph(testGraph)
//ich benötige flatMap nicht map weil
//ich kein 1: 1 Mapping habe
//im Graph mehrere digital Objects vorkommen können, weswegen ich eine Collection und nicht nur ein Objekt erhalte
.flatMap(v => Extractors.digitalObject(v.arr))
.isFailure
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment