Skip to content

Instantly share code, notes, and snippets.

@mgp
Created December 3, 2015 00:27
Show Gist options
  • Save mgp/b76958e4b965fe56aa60 to your computer and use it in GitHub Desktop.
Save mgp/b76958e4b965fe56aa60 to your computer and use it in GitHub Desktop.
//
// SearchFilterSequence.swift
// Khan Academy
//
// Created by Mike Parker on 12/2/15.
// Copyright © 2015 Khan Academy. All rights reserved.
//
import Foundation
public struct SearchFilterSequence {
public let values: [SearchFilter]
/// Returns the SearchFilter instances that are selected.
public var selectedFilters: [SearchFilter] {
return values.filter { $0.selected }
}
/// Returns whether the filter for offline content is selected.
public var isAvailableOfflineSelected: Bool {
return values.any { filter in
switch filter.predicate {
case .AvailableOfflinePredicate:
return filter.selected
default:
return false
}
}
}
/// Returns the domain names for the selected topic filters.
public var selectedTopicDomainNames: [String] {
return selectedFilters.flatMap { filter in
switch filter.predicate {
case .TopicPredicate:
return filter.localizedName
default:
return nil
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment