Skip to content

Instantly share code, notes, and snippets.

@filippovitale
Last active April 11, 2017 13:43
Show Gist options
  • Save filippovitale/573d42be6c09c97bd2ac80645bf1b2c3 to your computer and use it in GitHub Desktop.
Save filippovitale/573d42be6c09c97bd2ac80645bf1b2c3 to your computer and use it in GitHub Desktop.
Akka Stream Flow in Eta
{-# LANGUAGE MagicHash, TypeOperators, MultiParamTypeClasses, TypeFamilies, DataKinds, FlexibleContexts, OverloadedStrings, ScopedTypeVariables #-}
import Java
import Data.Char
import Data.Dynamic
import Data.Typeable
data {-# CLASS "akka.japi.function.Function" #-} Function t r = Function (Object# (Function t r))
deriving Class
foreign import java unsafe "@wrapper apply"
applyFunction :: (t <: Object, r <: Object) => (t -> Java (Function t r) r) -> Function t r
data {-# CLASS "akka.stream.javadsl.Flow" #-} Flow i o m = Flow (Object# (Flow i o m))
deriving Class
data {-# CLASS "akka.NotUsed" #-} NotUsed = NotUsed (Object# NotUsed)
deriving Class
-- public static <I,O> Flow<I,O,NotUsed> fromFunction(Function<I,O> f)
foreign import java unsafe "@static akka.stream.javadsl.Flow.fromFunction" flowFromFunction :: (t <: Object) => Function t t -> IO (Flow t t NotUsed)
main :: IO ()
main = do
flow <- flowFromFunction $ applyFunction f
return ()
where f = \(_ :: JString) -> return ("anonymous class" :: JString)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment