record
Custom Equality check for C# 9 records
Per the C#9 record proposal, the following should compile, even if not very useful without actual implementations.. // No explicit IEquatable<R> – this is synthesized! public sealed record SimpleVo { // Not virtual, as SimpleVo (R) is sealed. // Accepts SimpleVo? (R?), and not SimpleVo (R), as argument. public bool Equals(SimpleVo? other) => throw new … Read more
How to copy/clone records in C# 9?
But what about cloning? var r4 = r with { }; performs a shallow clone on r. The clone method is public according to the specification above. But what is its name? The C# compiler has a fairly common trick where it gives generated members names which are illegal in C#, but legal in IL, … Read more
Haskell record pattern matching
You can use record patterns like this: data X = A | B {name :: String} | C {x::Int, y::Int, name::String} myfn :: X -> Int myfn A = 50 myfn B{} = 200 myfn C{} = 500 Record patterns allow you to give names to the fields of the constructors. you can also do … Read more
Return a value if no record is found
Encapsulate the query in a sub-query to transform “no row” to a null value. I tested and verified this with PostgreSQL, SQLite, SQL Server, and MySQL. SELECT (SELECT id FROM tbl WHERE id = 9823474) AS id; In Oracle you have to select from the dummy 1-row table DUAL: SELECT (SELECT id FROM tbl WHERE … Read more
HowTo: Custom Field in Lift-Record-Squeryl
you are implementing your validation logic incorrectly. The correct way to validate a Record field is to override def validations: List[ValidationFunction] where ValidationFunction is a type alias type ValidationFunction = ValueType => List[FieldError] and in your case ValueType == String. The next issue is your Domain trait. Because your call to validate is inlined into … Read more
How to update a mongo record using Rogue with MongoCaseClassField when case class contains a scala Enumeration
Answer coming from : http://grokbase.com/t/gg/rogue-users/1367nscf80/how-to-update-a-record-with-mongocaseclassfield-when-case-class-contains-a-scala-enumeration#20130612woc3x7utvaoacu7tv7lzn4sr2q But more convenient directly here on StackOverFlow: Sorry, I should have chimed in here sooner. One of the long-standing problems with Rogue was that it was too easy to accidentally make a field that was not serializable as BSON, and have it fail at runtime (when you try to add … Read more
Shorthand way for assigning a single field in a record, while copying the rest of the fields?
Yes, there’s a nice way of updating record fields. In GHCi you can do — > data Foo = Foo { a :: Int, b :: Int, c :: String } — define a Foo > let foo = Foo { a = 1, b = 2, c = “Hello” } — create a Foo … Read more
lenses, fclabels, data-accessor – which library for structure access and mutation is better
There are at least 4 libraries that I am aware of providing lenses. The notion of a lens is that it provides something isomorphic to data Lens a b = Lens (a -> b) (b -> a -> a) providing two functions: a getter, and a setter get (Lens g _) = g put (Lens … Read more
SQL – Update multiple records in one query
Try either multi-table update syntax UPDATE config t1 JOIN config t2 ON t1.config_name=”name1″ AND t2.config_name=”name2″ SET t1.config_value=”value”, t2.config_value=”value2″; Here is a SQLFiddle demo or conditional update UPDATE config SET config_value = CASE config_name WHEN ‘name1’ THEN ‘value’ WHEN ‘name2’ THEN ‘value2’ ELSE config_value END WHERE config_name IN(‘name1’, ‘name2’); Here is a SQLFiddle demo