rizumita / Selm

Selm is the framework to realize Elm architecture in Swift
MIT License
13 stars 1 forks source link

Add Swiftz to Selm #7

Open kylelol opened 4 years ago

kylelol commented 4 years ago

Should we make SwiftZ library https://github.com/typelift/Swiftz a dependency of Selm instead of just the example project?

rizumita commented 4 years ago

@kylelol What are the possible features by depending on Swiftz?

kylelol commented 4 years ago

I think it would be nice to have a few operators like |>, <|, and (<<)
Those are the three that the Elm language provides to help with function composition. That way we can start making the implementation more functional.

For example I could change the map function on Task<A> from an instance function to a static function, and made it curried

// In Task<A>
static func map<A, B>(_ transform: @escaping (A) -> B) -> (Task<A>) -> Task<B> { 
...
}

// At call site 
let transform = { someA in return someB }
let taskA = Task<A>()
let taskB = taskA |> Task.map(transform)

I'd be open to just implementing the operators ourselves, but I saw you included the Swiftz dependency in the example project, so I was not sure if it made sense to just move it to Selm

rizumita commented 4 years ago

@kylelol Selm becomes handy probably, as you say. Would you write Selm code with Swiftz?

kylelol commented 4 years ago

@rizumita I honestly would probably only want to use those 3 operators I mentioned above |>, <|, and •(<<) inside Selm code for now.

rizumita commented 4 years ago

@kylelol If only operators, I think Selm depends only on Swiftx perhaps. Do we need a Monad by depending on Swiftz?

kylelol commented 4 years ago

@rizumita I would probably not need a Monad from swifz.
I would more than likely just implement the functions required for a Monad myself, such as bind

rizumita commented 4 years ago

@kylelol OK, let's use a suitable one, either Swiftx or Swiftz.