From 3091ee024a0e18643d09a15d5181ee345ac764d6 Mon Sep 17 00:00:00 2001 From: Tae Won Ha Date: Sat, 16 Dec 2017 14:02:51 +0100 Subject: [PATCH] Add extension stream method --- NvimView/NvimView/NvimApiExtension.swift | 25 +++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/NvimView/NvimView/NvimApiExtension.swift b/NvimView/NvimView/NvimApiExtension.swift index 18be9ba6..b09979aa 100644 --- a/NvimView/NvimView/NvimApiExtension.swift +++ b/NvimView/NvimView/NvimApiExtension.swift @@ -5,6 +5,7 @@ import Foundation import NvimMsgPack +import RxSwift extension NvimApi { @@ -34,6 +35,28 @@ extension NvimApi { } } +extension StreamApi { + + public func getBufGetInfo( + buffer: NvimApi.Buffer + ) -> Single> { + + let params: [NvimApi.Value] = [ + .int(Int64(buffer.handle)), + ] + + return self + .rpc(method: "nvim_buf_get_info", params: params, expectsReturnValue: true) + .map { + guard let result = (msgPackDictToSwift($0.dictionaryValue)) else { + throw NvimApi.Error.conversion(type: Dictionary.self) + } + + return result + } + } +} + func msgPackDictToSwift(_ dict: Dictionary?) -> Dictionary? { return dict?.flatMapToDict { k, v in guard let strKey = k.stringValue else { @@ -57,7 +80,7 @@ extension Dictionary { return tuplesToDict(array) } - fileprivate func tuplesToDict(_ sequence: S) + fileprivate func tuplesToDict(_ sequence: S) -> Dictionary where S.Iterator.Element == (K, V) { var result = Dictionary(minimumCapacity: sequence.underestimatedCount)