I hereby claim:
- I am broomburgo on github.
- I am exfalsoquodlibet (https://keybase.io/exfalsoquodlibet) on keybase.
- I have a public key ASAuzWzq58xCzRHDw1zXAgExuqQExmZp-gDUT74iawJv8Ao
To claim this, I am signing this object:
I hereby claim:
To claim this, I am signing this object:
Answer to http://disq.us/p/1za4u75.
Hi, your problem is actually quite hard to solve with composition, at least without a profunctor-based approach, which is really hard to do in Swift due to the lack of higher-kinded types.
There is a solution, though, but we must be clear about what we're searching for here. In your ViewState<T>
there could be no Prism
that points just to T
, because the inject
function wouldn't know what case
to produce with a value of type T
: it's probably going to be an Affine
.
At the bottom of this answer you'll find all the code needed to implement it: it can be directly copy-pasted into a playground.
protocol TaggedType { | |
associatedtype TagType | |
} | |
protocol TypeConstructor1: TaggedType { | |
associatedtype ParameterType1 | |
} | |
protocol TypeConstructor2: TypeConstructor1 { | |
associatedtype ParameterType2 |
/// source: https://broomburgo.github.io/fun-ios/post/lenses-and-prisms-in-swift-a-pragmatic-approach/ | |
protocol LensType { | |
associatedtype WholeType | |
associatedtype PartType | |
var get: (WholeType) -> PartType { get } | |
var set: (PartType,WholeType) -> WholeType { get } | |
init(get: @escaping (WholeType) -> PartType, set: @escaping (PartType,WholeType) -> WholeType) |
feedbackModelController.deltaSignal | |
.filter { $0.feedback.rawValue < $1.feedback.rawValue} | |
.filter { $1.feedback == .Good || $1.feedback == .ReallyGood } | |
.onReception § eachTime § inAnyCase § showThankYouAlert |
func collectFeedbackModelChange() -> Signal<FeedbackModelChange> { | |
return pageFactory.signalMakeMainPage | |
.flatMap { $0.signalPolarizedChanged } | |
.map(FeedbackModel.transformWithPolarized) | |
+ pageFactory.signalMakeSelectionPage | |
.flatMap { $0.signalSelection } | |
.map(FeedbackModel.transformWithFeedback) | |
} |
pageFactory.signalMakeMainPage | |
.flatMap { $0.signalLeaveFeedback } | |
.onReception § eachTime § inAnyCase § presentSelectionPage | |
pageFactory.signalMakeSelectionPage | |
.flatMap { $0.signalSelection } | |
.onReception § eachTime § inAnyCase § popTopPage |
/// MainPage initializer | |
init(feedbackModelController: ModelController<FeedbackModel>) { | |
super.init(nibName: nil, bundle: nil) | |
feedbackModelController.updateSignal.onReception § eachTime § updateViewsWithFeedbackModel | |
viewReadyEmitter.signal.onReception § eachTime § feedbackModelController.notify | |
} |
import Foundation | |
public enum Persistence { | |
case Stop | |
case Continue | |
} | |
public final class Signal<Subtype> { | |
typealias Observation = Subtype -> Persistence | |
#import <Foundation/Foundation.h> | |
NS_ASSUME_NONNULL_BEGIN | |
@interface Optional : NSObject | |
+ (Optional*)with:(id _Nullable)value; | |
+ (Optional*)with:(id _Nullable)value as:(Class _Nonnull)valueClass; |