generics

Decoding object with multiple constuctors with separated tags

江枫思渺然 提交于 2020-04-16 03:27:07
问题 I have data in form of pairs of two strings, where first is the key identifying shape of the JSON delivered as the second one. fooooo {"a": 123} barrrr {"a": 123, "b": 123} fooooo {"a": 123} I would like to parse it to same data type, based on the fopooo , baasdasda1 , etc : data Test = Foo { a :: Int , b :: Int } | Bar { a :: Int } deriving (Show, Generic) In the Aeson there is a tag feature, but it seems to require presence of the tag inside the object. Is there some way to handle it like

Create a generic list in xaml 4.5+

╄→尐↘猪︶ㄣ 提交于 2020-04-13 17:17:15
问题 I am trying to make a rule list for one of my usercontrols. List contains a custom type List<StringInputRule> . I am using DependancyProperty to databind. I am trying to set the rules in xaml for the control as such: <controlsDefault:DateEditWithStringInput> <controlsDefault:DateEditWithStringInput.Rules> <x:Array Type="controlsDefault:StringInputRule" xmlns:sys="clr-namespace:System;assembly=mscorlib"> <controlsDefault:StringInputRule Key="T" Amount="1" Unit="Day"/> <controlsDefault

In Rust, what's the idiomatic way to split a &str into an iterator of &strs of one character each?

烂漫一生 提交于 2020-04-13 14:52:16
问题 If I want to take a &str like "aeiou" and turn it into an iterator roughly equivalent to ["a", "e", "i", "o", "u"].iter() , what's the most idiomatic way to do it? I've tried doing "aeiou".split("") which seemed idiomatic to me, but I got empty &str s at the beginning and end. I've tried doing "aeiou".chars() but it got pretty ugly and unwieldy from there trying to turn the char s into &str s. For the time being, I just typed out ["a", "e", "i", "o", "u"].iter() , but there's got to be an

In Rust, what's the idiomatic way to split a &str into an iterator of &strs of one character each?

落爺英雄遲暮 提交于 2020-04-13 14:51:09
问题 If I want to take a &str like "aeiou" and turn it into an iterator roughly equivalent to ["a", "e", "i", "o", "u"].iter() , what's the most idiomatic way to do it? I've tried doing "aeiou".split("") which seemed idiomatic to me, but I got empty &str s at the beginning and end. I've tried doing "aeiou".chars() but it got pretty ugly and unwieldy from there trying to turn the char s into &str s. For the time being, I just typed out ["a", "e", "i", "o", "u"].iter() , but there's got to be an

Represent generic class inheritance in UML

大憨熊 提交于 2020-04-11 12:07:32
问题 Is this the correct way to represent the following code in a UML Class Diagram? CODE: public class CustomerRepository : EntityFrameworkRepository<Customer>, ICustomerRepository { } UML: 回答1: EDIT: Realised first answer wasn't correct after posting. The UML spec says (section 7.3.4): A bound element has the same graphical notation as other Elements of that kind. A TemplateBinding is shown as a dashed arrow with the tail on the bound element and the arrowhead on the template and the keyword

Represent generic class inheritance in UML

隐身守侯 提交于 2020-04-11 12:06:23
问题 Is this the correct way to represent the following code in a UML Class Diagram? CODE: public class CustomerRepository : EntityFrameworkRepository<Customer>, ICustomerRepository { } UML: 回答1: EDIT: Realised first answer wasn't correct after posting. The UML spec says (section 7.3.4): A bound element has the same graphical notation as other Elements of that kind. A TemplateBinding is shown as a dashed arrow with the tail on the bound element and the arrowhead on the template and the keyword

Represent generic class inheritance in UML

ⅰ亾dé卋堺 提交于 2020-04-11 12:06:13
问题 Is this the correct way to represent the following code in a UML Class Diagram? CODE: public class CustomerRepository : EntityFrameworkRepository<Customer>, ICustomerRepository { } UML: 回答1: EDIT: Realised first answer wasn't correct after posting. The UML spec says (section 7.3.4): A bound element has the same graphical notation as other Elements of that kind. A TemplateBinding is shown as a dashed arrow with the tail on the bound element and the arrowhead on the template and the keyword

Using named tuples in select statements

旧街凉风 提交于 2020-04-10 07:13:05
问题 Is there a nicer way to select a named tuple in C# 7 using a var target variable? I must be doing something wrong in example 1, or misunderstanding something completely. I seem to have to explicitly set the target type in order to do this. //1. Fails to compile with "incorrect number of type parameters" issue. var tuples = source.Select<(int A, int B)>(x => (x.A, x.B)); //2. Compiles IEnumerable<(int A, int B)> tuples = toCheck.Select(x => (x.A, x.B)); //3. Compiles var tuples = new HashSet<

Using named tuples in select statements

五迷三道 提交于 2020-04-10 07:09:07
问题 Is there a nicer way to select a named tuple in C# 7 using a var target variable? I must be doing something wrong in example 1, or misunderstanding something completely. I seem to have to explicitly set the target type in order to do this. //1. Fails to compile with "incorrect number of type parameters" issue. var tuples = source.Select<(int A, int B)>(x => (x.A, x.B)); //2. Compiles IEnumerable<(int A, int B)> tuples = toCheck.Select(x => (x.A, x.B)); //3. Compiles var tuples = new HashSet<

java: Use of Raw type as method parameter errases all parametrized type information in parameter members

青春壹個敷衍的年華 提交于 2020-04-06 07:34:26
问题 Please explain me why if I use the raw type A in the method test() , the get() method on my typed list returns an Object and not a B.: public class test { public class B{} public class C{} public class A<T extends C> { private List<B> aBList; public List<B> mGetBList() { return aBList; } } public test(A pA) // Use of raw type - this is bad, I know! { B lB = pA.mGetBList().get(0); // Compile error: Type mismatch: // cannot convert from Object to test.B } } If I declare public test(A<?> pA) the