mirror of
https://github.com/divkit/divkit.git
synced 2026-05-07 20:02:32 +00:00
26 lines
703 B
Swift
26 lines
703 B
Swift
import CommonCore
|
|
import LayoutKit
|
|
|
|
extension Array where Element == Div {
|
|
func makeBlocks<T>(
|
|
context: DivBlockModelingContext,
|
|
mappedBy modificator: (Div, Block) throws -> T
|
|
) throws -> [T] {
|
|
try iterativeFlatMap { div, index in
|
|
let itemContext = modified(context) { $0.parentPath += index }
|
|
let block: Block
|
|
do {
|
|
block = try div.value.makeBlock(context: itemContext)
|
|
} catch {
|
|
DivKitLogger.error("Failed to create block: \(error)")
|
|
return nil
|
|
}
|
|
return try modificator(div, block)
|
|
}
|
|
}
|
|
|
|
func makeBlocks(context: DivBlockModelingContext) throws -> [Block] {
|
|
try makeBlocks(context: context, mappedBy: { $1 })
|
|
}
|
|
}
|