Skip to content

Commit 4359e9b

Browse files
committed
Cleanups
1 parent 0a5db1f commit 4359e9b

File tree

11 files changed

+139
-136
lines changed

11 files changed

+139
-136
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
2+
<s:Boolean x:Key="/Default/UserDictionary/Words/=hkey/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>

src/FSharp.AWS.DynamoDB/Expression/ConditionalExpr.fs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ let extractKeyCondition (qExpr: QueryExpr) =
144144
| None ->
145145
hk.KeySchemata
146146
|> Array.tryPick (function
147-
| (ks, KeyType.Hash) -> Some ks
147+
| ks, KeyType.Hash -> Some ks
148148
| _ -> None)
149149
| Some rk ->
150150
Seq.joinBy (fun (ks, kt) (ks', kt') -> kt = KeyType.Hash && kt' = KeyType.Range && ks = ks') hk.KeySchemata rk.KeySchemata
@@ -163,7 +163,7 @@ let ensureNotTautological query =
163163
let extractQueryExpr (recordInfo: RecordTableInfo) (expr: Expr) : ConditionalExpression =
164164
if not expr.IsClosed then
165165
invalidArg "expr" "supplied query is not a closed expression."
166-
let invalidQuery () = invalidArg "expr" <| sprintf "Supplied expression is not a valid conditional."
166+
let invalidQuery () = invalidArg "expr" "Supplied expression is not a valid conditional."
167167

168168
let nParams, (|PVar|_|), expr' = extractExprParams recordInfo expr
169169

@@ -233,12 +233,12 @@ let extractQueryExpr (recordInfo: RecordTableInfo) (expr: Expr) : ConditionalExp
233233
let (|Comparison|_|) (pat: Expr) (expr: Expr) =
234234
match expr with
235235
| SpecificCall pat (None, _, args) ->
236-
let pickler = args |> List.tryPick (|AttributeGet|_|) |> Option.map (fun attr -> attr.Pickler)
236+
let pickler = args |> List.tryPick (|AttributeGet|_|) |> Option.map _.Pickler
237237
let operands = args |> List.map (extractOperand pickler)
238238
let pickler =
239239
match pickler with
240240
| Some p -> p
241-
| None -> Pickler.resolveUntyped args.[0].Type
241+
| None -> Pickler.resolveUntyped args[0].Type
242242
Some(pickler, operands)
243243

244244
| _ -> None
@@ -354,7 +354,7 @@ let applyParams (cond: ConditionalExpression) (inputValues: obj[]) =
354354
let applyOperand (op: Operand) =
355355
match op with
356356
| Param(i, pickler) ->
357-
match pickler.PickleCoerced inputValues.[i] with
357+
match pickler.PickleCoerced inputValues[i] with
358358
| Some av -> Value(wrap av)
359359
| None -> Undefined
360360

@@ -396,7 +396,7 @@ let applyParams (cond: ConditionalExpression) (inputValues: obj[]) =
396396

397397
/// prints a query expression to string recognizable by the DynamoDB APIs
398398
let writeConditionExpression (writer: AttributeWriter) (cond: ConditionalExpression) =
399-
let sb = new System.Text.StringBuilder()
399+
let sb = System.Text.StringBuilder()
400400
let inline (!) (p: string) = sb.Append p |> ignore
401401
let inline writeOp o =
402402
match o with
@@ -411,12 +411,12 @@ let writeConditionExpression (writer: AttributeWriter) (cond: ConditionalExpress
411411

412412
let writeOps (ops: Operand array) =
413413
if ops.Length = 1 then
414-
writeOp ops.[0]
414+
writeOp ops[0]
415415
else
416416
for i = 0 to ops.Length - 2 do
417-
writeOp ops.[i]
417+
writeOp ops[i]
418418
! ", "
419-
writeOp ops.[ops.Length - 1]
419+
writeOp ops[ops.Length - 1]
420420

421421

422422
let inline writeCmp cmp =

src/FSharp.AWS.DynamoDB/Expression/ExprCommon.fs

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ type NestedAttribute =
2525
member nf.Print() =
2626
match nf with
2727
| FParam i -> sprintf "<$param%d>" i
28-
| FField f when not <| isValidFieldName f -> sprintf "map keys must be 1 to 64k long (as utf8)." |> invalidArg f
28+
| FField f when not <| isValidFieldName f -> invalidArg f "map keys must be 1 to 64k long (as utf8)."
2929
| FField f -> "." + f
3030
| FIndex i -> sprintf "[%d]" i
3131

@@ -56,43 +56,43 @@ type AttributeId =
5656

5757
member id.Tokens = seq {
5858
yield id.RootName
59-
yield! id.NestedAttributes |> Seq.map (fun nf -> nf.Print())
59+
yield! id.NestedAttributes |> Seq.map _.Print()
6060
}
6161

6262
member id.IsHashKey =
6363
List.isEmpty id.NestedAttributes
6464
&& id.KeySchemata
6565
|> Array.exists (function
66-
| (_, KeyType.Hash) -> true
66+
| _, KeyType.Hash -> true
6767
| _ -> false)
6868

6969
member id.IsRangeKey =
7070
List.isEmpty id.NestedAttributes
7171
&& id.KeySchemata
7272
|> Array.exists (function
73-
| (_, KeyType.Range) -> true
73+
| _, KeyType.Range -> true
7474
| _ -> false)
7575

7676
member id.IsPrimaryKey =
7777
List.isEmpty id.NestedAttributes
7878
&& id.KeySchemata
7979
|> Array.exists (function
80-
| ({ Type = PrimaryKey }, _) -> true
80+
| { Type = PrimaryKey }, _ -> true
8181
| _ -> false)
8282

8383
member id.Append nf = { id with NestedAttributes = id.NestedAttributes @ [ nf ] }
8484
member id.Apply(inputs: obj[]) =
8585
let applyField nf =
8686
match nf with
8787
| FParam i ->
88-
match inputs.[i] with
88+
match inputs[i] with
8989
| :? string as f -> FField f
9090
| :? int as i ->
9191
if i < 0 then
9292
raise <| ArgumentOutOfRangeException()
9393
else
9494
FIndex i
95-
| _ -> raise <| new InvalidCastException()
95+
| _ -> raise <| InvalidCastException()
9696
| _ -> nf
9797

9898
{ id with NestedAttributes = id.NestedAttributes |> List.map applyField }
@@ -107,7 +107,7 @@ type AttributeId =
107107

108108
type PropertyMetadata with
109109

110-
/// Gets an attribute Id for given record property that
110+
/// Gets an attribute id for given record property that
111111
/// is recognizable by DynamoDB
112112
member rp.AttrId = sprintf "#ATTR%d" rp.Index
113113

@@ -137,7 +137,7 @@ type QuotedAttribute =
137137

138138
aux ap
139139

140-
/// Gets an attribute identifier for given Quoted attribute instace
140+
/// Gets an attribute identifier for given Quoted attribute instance
141141
member ap.Id =
142142
let rec getTokens acc ap =
143143
match ap with
@@ -250,30 +250,29 @@ type QuotedAttribute =
250250
/// Wrapper API for writing attribute names and values for Dynamo query, update and condition expressions
251251
/// Responsible for generating unique placeholders for attribute names and values
252252
type AttributeWriter(names: Dictionary<string, string>, values: Dictionary<string, AttributeValue>) =
253-
static let cmp = new AttributeValueComparer()
254-
let vcontents = new Dictionary<AttributeValue, string>(cmp)
253+
static let cmp = AttributeValueComparer()
254+
let ids = Dictionary<AttributeValue, string>(cmp)
255255

256256
new() = AttributeWriter(Dictionary(), Dictionary())
257257

258258
member _.Names= if names.Count = 0 then null else names
259259
member _.Values = if values.Count = 0 then null else values
260260

261261
member _.WriteValue(av: AttributeValue) =
262-
let ok, found = vcontents.TryGetValue av
263-
if ok then
264-
found
265-
else
262+
match ids.TryGetValue av with
263+
| true, id -> id
264+
| false, _ ->
266265
let id = sprintf ":val%d" values.Count
267-
vcontents.Add(av, id)
266+
ids.Add(av, id)
268267
values.Add(id, av)
269268
id
270269
member _.WriteAttribute(attr: AttributeId) =
271270
names[attr.RootId] <- attr.RootName
272271
attr.Id
273272

274-
/// Recognizes exprs of shape <@ fun p1 p2 ... -> body @>
273+
/// Recognizes Expr values of shape <@ fun p1 p2 ... -> body @>
275274
let extractExprParams (recordInfo: RecordTableInfo) (expr: Expr) =
276-
let vars = new Dictionary<Var, int>()
275+
let vars = Dictionary<Var, int>()
277276
let rec aux i expr =
278277
match expr with
279278
| Lambda(v, body) when v.Type <> recordInfo.Type ->
@@ -297,26 +296,26 @@ let extractExprParams (recordInfo: RecordTableInfo) (expr: Expr) =
297296
type private AttributeNode = { Value: string; Children: ResizeArray<AttributeNode> }
298297
/// Detects conflicts in a collection of attribute paths
299298
let tryFindConflictingPaths (attrs: seq<AttributeId>) =
300-
let root = new ResizeArray<AttributeNode>()
299+
let root = ResizeArray<AttributeNode>()
301300
let tryAppendPath (attr: AttributeId) =
302301
let tokens = attr.Tokens
303302
let enum = tokens.GetEnumerator()
304303
let mutable ctx = root
305304
let mutable isNodeAdded = false
306305
let mutable isLeafFound = false
307-
let acc = new ResizeArray<_>()
306+
let acc = ResizeArray<_>()
308307
while not isLeafFound && enum.MoveNext() do
309308
let t = enum.Current
310309
let child =
311310
match ctx.FindIndex(fun n -> n.Value = t) with
312311
| -1 ->
313312
isNodeAdded <- true
314-
let ch = { Value = t; Children = new ResizeArray<_>() }
313+
let ch = { Value = t; Children = ResizeArray<_>() }
315314
ctx.Add ch
316315
ch
317316

318317
| i ->
319-
let ch = ctx.[i]
318+
let ch = ctx[i]
320319
if ch.Children.Count = 0 then
321320
isLeafFound <- true
322321
ch
@@ -329,7 +328,7 @@ let tryFindConflictingPaths (attrs: seq<AttributeId>) =
329328
Some(concat tokens, concat acc)
330329
elif not isNodeAdded then
331330
while ctx.Count > 0 do
332-
let ch = ctx.[0]
331+
let ch = ctx[0]
333332
acc.Add ch.Value
334333
ctx <- ch.Children
335334

src/FSharp.AWS.DynamoDB/Expression/ProjectionExpr.fs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ type AttributeId with
4747
if i < 0 || i >= av.L.Count then
4848
sprintf "Indexed path '%s' out of range." id.Name |> ArgumentOutOfRangeException |> raise
4949
else
50-
aux result tl av.L.[i]
50+
aux result tl av.L[i]
5151
else
5252
av.Print() |> sprintf "Expected list, but was '%s'." |> InvalidCastException |> raise
5353

@@ -107,8 +107,8 @@ type ProjectionExpr =
107107
| _ -> invalidExpr ())
108108
|> Seq.toArray
109109

110-
let attrs = qAttrs |> Array.map (fun qa -> qa.Id)
111-
let picklers = qAttrs |> Array.map (fun qa -> qa.Pickler)
110+
let attrs = qAttrs |> Array.map _.Id
111+
let picklers = qAttrs |> Array.map _.Pickler
112112

113113
// check for conflicting projection attributes
114114
match tryFindConflictingPaths attrs with
@@ -123,11 +123,11 @@ type ProjectionExpr =
123123
let values = Array.zeroCreate<obj> attrs.Length
124124
for i = 0 to attrs.Length - 1 do
125125
let mutable av = null
126-
let ok = attrs.[i].View(ro, &av)
126+
let ok = attrs[i].View(ro, &av)
127127
if ok then
128-
values.[i] <- picklers.[i].UnPickleUntyped av
128+
values[i] <- picklers[i].UnPickleUntyped av
129129
else
130-
values.[i] <- picklers.[i].DefaultValueUntyped
130+
values[i] <- picklers[i].DefaultValueUntyped
131131

132132
tupleCtor values
133133

@@ -137,7 +137,7 @@ type ProjectionExpr =
137137
| _ -> invalidExpr ()
138138

139139
member __.Write(writer: AttributeWriter) =
140-
let sb = new System.Text.StringBuilder()
140+
let sb = System.Text.StringBuilder()
141141
let inline (!) (x: string) = sb.Append x |> ignore
142142
let mutable isFirst = true
143143
for attr in __.Attributes do

src/FSharp.AWS.DynamoDB/Expression/UpdateExpr.fs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ type UpdateOperation with
141141
let extractRecordExprUpdaters (recordInfo: RecordTableInfo) (expr: Expr) : IntermediateUpdateExprs =
142142
if not expr.IsClosed then
143143
invalidArg "expr" "supplied update expression contains free variables."
144-
let invalidExpr () = invalidArg "expr" <| sprintf "Supplied expression is not a valid update expression."
144+
let invalidExpr () = invalidArg "expr" "Supplied expression is not a valid update expression."
145145

146146
let nParams, pRecognizer, expr' = extractExprParams recordInfo expr
147147

@@ -156,10 +156,10 @@ let extractRecordExprUpdaters (recordInfo: RecordTableInfo) (expr: Expr) : Inter
156156
let bindings, assignments = stripBindings Map.empty body
157157

158158
let tryExtractValueExpr (i: int) (assignment: Expr) =
159-
let rp = recordInfo.Properties.[i]
159+
let rp = recordInfo.Properties[i]
160160
match assignment with
161161
| PropertyGet(Some(Var y), prop, []) when r = y && rp.PropertyInfo = prop -> None
162-
| Var v when bindings.ContainsKey v -> Some(Root(rp, recordInfo.GetPropertySchemata rp.Name), bindings.[v])
162+
| Var v when bindings.ContainsKey v -> Some(Root(rp, recordInfo.GetPropertySchemata rp.Name), bindings[v])
163163
| e -> Some(Root(rp, recordInfo.GetPropertySchemata rp.Name), e)
164164

165165
let assignmentExprs = assignments |> Seq.mapi tryExtractValueExpr |> Seq.choose id |> Seq.toArray
@@ -178,7 +178,7 @@ let extractRecordExprUpdaters (recordInfo: RecordTableInfo) (expr: Expr) : Inter
178178
let extractOpExprUpdaters (recordInfo: RecordTableInfo) (expr: Expr) : IntermediateUpdateExprs =
179179
if not expr.IsClosed then
180180
invalidArg "expr" "supplied update expression contains free variables."
181-
let invalidExpr () = invalidArg "expr" <| sprintf "Supplied expression is not a valid update expression."
181+
let invalidExpr () = invalidArg "expr" "Supplied expression is not a valid update expression."
182182

183183
let nParams, (|PVar|_|), expr' = extractExprParams recordInfo expr
184184

@@ -196,9 +196,9 @@ let extractOpExprUpdaters (recordInfo: RecordTableInfo) (expr: Expr) : Intermedi
196196
match expr' with
197197
| Lambda(r, body) when r.Type = recordInfo.Type ->
198198
let (|AttributeGet|_|) (e: Expr) = QuotedAttribute.TryExtract (|PVar|_|) r recordInfo e
199-
let attrs = new ResizeArray<QuotedAttribute>()
200-
let assignments = new ResizeArray<QuotedAttribute * Expr>()
201-
let updateOps = new ResizeArray<UpdateOperation>()
199+
let attrs = ResizeArray<QuotedAttribute>()
200+
let assignments = ResizeArray<QuotedAttribute * Expr>()
201+
let updateOps = ResizeArray<UpdateOperation>()
202202
let rec extract e =
203203
match e with
204204
| SpecificCall2 <@ (&&&) @> (None, _, _, [ l; r ]) ->
@@ -227,7 +227,7 @@ let extractOpExprUpdaters (recordInfo: RecordTableInfo) (expr: Expr) : Intermedi
227227

228228
do extract body
229229

230-
match attrs |> Seq.map (fun attr -> attr.Id) |> tryFindConflictingPaths with
230+
match attrs |> Seq.map _.Id |> tryFindConflictingPaths with
231231
| Some(p1, p2) ->
232232
let msg = sprintf "found conflicting paths '%s' and '%s' being accessed in update expression." p1 p2
233233
invalidArg "expr" msg
@@ -248,7 +248,7 @@ let extractOpExprUpdaters (recordInfo: RecordTableInfo) (expr: Expr) : Intermedi
248248

249249
/// Completes conversion from intermediate update expression to final update operations
250250
let extractUpdateOps (exprs: IntermediateUpdateExprs) =
251-
let invalidExpr () = invalidArg "expr" <| sprintf "Supplied expression is not a valid update expression."
251+
let invalidExpr () = invalidArg "expr" "Supplied expression is not a valid update expression."
252252
let (|PVar|_|) = exprs.ParamRecognizer
253253
let (|AttributeGet|_|) (e: Expr) = QuotedAttribute.TryExtract (|PVar|_|) exprs.RVar exprs.RecordInfo e
254254

@@ -368,7 +368,7 @@ let applyParams (uops: UpdateOperations) (inputValues: obj[]) =
368368
let applyOperand (op: Operand) =
369369
match op with
370370
| Param(i, pickler) ->
371-
match pickler.PickleCoerced inputValues.[i] with
371+
match pickler.PickleCoerced inputValues[i] with
372372
| Some av -> Value(wrap av)
373373
| None -> Undefined
374374

@@ -405,7 +405,7 @@ let applyParams (uops: UpdateOperations) (inputValues: obj[]) =
405405
/// prints a set of update operations to string recognizable by the DynamoDB APIs
406406
let writeUpdateExpression (writer: AttributeWriter) (uops: UpdateOperations) =
407407

408-
let sb = new System.Text.StringBuilder()
408+
let sb = System.Text.StringBuilder()
409409
let inline (!) (s: string) = sb.Append s |> ignore
410410

411411
let inline writeAttr attr = !(writer.WriteAttribute attr)

0 commit comments

Comments
 (0)