enumerator

Get fullpath or convert to fullpath

喜你入骨 提交于 2019-11-29 17:48:06
When using let directoryEnumerator = FileManager().enumerator(at: ... in Swift 3, I get all files from the folder, e.g. "file:///Volumes/MacOS/fasttemp/Fotos/" The results are not including the leading path (here "/Volumes/MacOS"). So I get "file:///fasttemp/Fotos/2005/" How can I get the fullpath (directly from the enumerator) or convert them. I want to use URL functions, not string function manipulating by assumptions. If "MacOS" is the name of your current startup disk then "/Volumes/MacOS" is a symbolic link to "/", so both "/fasttemp/Fotos/2005/" and "/Volumes/MacOS/fasttemp/Fotos/" are

Sharing an enumerator across threads

倖福魔咒の 提交于 2019-11-29 10:45:08
I want to call a common enumerator from different threads. When I do the following, enum = (0..1000).to_enum t1 = Thread.new do p enum.next sleep(1) end t2 = Thread.new do p enum.next sleep(1) end t1.join t2.join it raises an error: Fiber called across threads. when enum is called from t2 after once being called from t1 . Why is Ruby designed to not allow an enumerator (or fiber) to be called across threads, and Is there an alternative way to provide a similar function? I am guessing that atomicity of an operation on an enumerator/fiber is relevant here, but am not fully sure. If that is the

Type signature in a where clause

拈花ヽ惹草 提交于 2019-11-29 06:00:35
I've written a function similar to Data.Enumerator.List.map that makes an Iteratee compatible with an Enumerator that feeds a different Stream type. import Data.Enumerator test :: Monad m => (ao -> ai) -> Iteratee ai m b -> Iteratee ao m b test f iter = go $$ iter where go (Continue k) = continue $ \stream -> go $$ k (fmap f stream) go (Yield res _) = yield res EOF If I omit the type signature for go , this will work just fine. However, I'd like to include it but I'm unable to determine what the correct signature should be. Here's what I think it should be: go :: Monad m => Step ai m b ->

Get next N elements from enumerable

99封情书 提交于 2019-11-29 03:51:51
Context: C# 3.0, .Net 3.5 Suppose I have a method that generates random numbers (forever): private static IEnumerable<int> RandomNumberGenerator() { while (true) yield return GenerateRandomNumber(0, 100); } I need to group those numbers in groups of 10, so I would like something like: foreach (IEnumerable<int> group in RandomNumberGenerator().Slice(10)) { Assert.That(group.Count() == 10); } I have defined Slice method, but I feel there should be one already defined. Here is my Slice method, just for reference: private static IEnumerable<T[]> Slice<T>(IEnumerable<T> enumerable, int size) { var

How to iterate over two arrays at once?

萝らか妹 提交于 2019-11-28 21:29:31
I have two arrays built while parsing a text file. The first contains the column names, the second contains the values from the current row. I need to iterate over both lists at once to build a map. Right now I have the following: var currentValues = currentRow.Split(separatorChar); var valueEnumerator = currentValues.GetEnumerator(); foreach (String column in columnList) { valueEnumerator.MoveNext(); valueMap.Add(column, (String)valueEnumerator.Current); } This works just fine, but it doesn't quite satisfy my sense of elegance, and it gets really hairy if the number of arrays is larger than

Get fullpath or convert to fullpath

萝らか妹 提交于 2019-11-28 12:49:41
问题 When using let directoryEnumerator = FileManager().enumerator(at: ... in Swift 3, I get all files from the folder, e.g. "file:///Volumes/MacOS/fasttemp/Fotos/" The results are not including the leading path (here "/Volumes/MacOS"). So I get "file:///fasttemp/Fotos/2005/" How can I get the fullpath (directly from the enumerator) or convert them. I want to use URL functions, not string function manipulating by assumptions. 回答1: If "MacOS" is the name of your current startup disk then "/Volumes

Sharing an enumerator across threads

我的梦境 提交于 2019-11-28 03:52:34
问题 I want to call a common enumerator from different threads. When I do the following, enum = (0..1000).to_enum t1 = Thread.new do p enum.next sleep(1) end t2 = Thread.new do p enum.next sleep(1) end t1.join t2.join it raises an error: Fiber called across threads. when enum is called from t2 after once being called from t1 . Why is Ruby designed to not allow an enumerator (or fiber) to be called across threads, and Is there an alternative way to provide a similar function? I am guessing that

Get next N elements from enumerable

二次信任 提交于 2019-11-27 17:53:26
问题 Context: C# 3.0, .Net 3.5 Suppose I have a method that generates random numbers (forever): private static IEnumerable<int> RandomNumberGenerator() { while (true) yield return GenerateRandomNumber(0, 100); } I need to group those numbers in groups of 10, so I would like something like: foreach (IEnumerable<int> group in RandomNumberGenerator().Slice(10)) { Assert.That(group.Count() == 10); } I have defined Slice method, but I feel there should be one already defined. Here is my Slice method,

How can a formcollection be enumerated in ASP.NET MVC?

守給你的承諾、 提交于 2019-11-26 10:21:56
问题 How can I enumerate through all the key/values of a FormCollection (system.web.mvc) in ASP.NET MVC? 回答1: Here are 3 ways to do it specifically with a FormCollection object. public ActionResult SomeActionMethod(FormCollection formCollection) { foreach (var key in formCollection.AllKeys) { var value = formCollection[key]; } foreach (var key in formCollection.Keys) { var value = formCollection[key.ToString()]; } // Using the ValueProvider var valueProvider = formCollection.ToValueProvider();