WaveBeans / wavebeans

Audio Processing. On scale.
https://wavebeans.io
Apache License 2.0
24 stars 0 forks source link

Custom alter functions #13

Closed asubb closed 4 years ago

asubb commented 4 years ago

User should be able to define the functions that will be applied on the stream, the aim of this function is to modify the content stream in a custom way

API examples

On sample stream

sampleStream
  .alter { it * 2 }

On windowed sample stream

sampleStream
  .window(N)
  .alter { window -> window.map { window.last() }  }

Alter function signature: (T) -> T

asubb commented 4 years ago

A little investigation how it can be serialized for topology, however it should appear under the exactly same name

import kotlin.reflect.jvm.jvmName

val func: (Long) -> Long = { it * 2 }

println(func(2))
// outputs 4

val funcClass = func::class
val funcClassAsString = funcClass.jvmName

println(funcClassAsString)
// outputs class name

val clazz = Class.forName(funcClassAsString)
val funcByName = clazz.newInstance() as (Any) -> Any

println(funcByName(2))
// outputs 4
asubb commented 4 years ago

Implementation will be common with https://github.com/asubb/wavebeans/issues/16

asubb commented 4 years ago

Implemented in https://github.com/asubb/wavebeans/pull/19