Skip to content

Commit 3ffbd07

Browse files
committed
Cleanups
1 parent 0a5db1f commit 3ffbd07

File tree

3 files changed

+41
-40
lines changed

3 files changed

+41
-40
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/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 -> "map keys must be 1 to 64k long (as utf8)." |> invalidArg f
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, value -> value
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/TableContext.fs

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -263,9 +263,9 @@ type TableContext<'TRecord>
263263
match proj with
264264
| None -> ()
265265
| Some proj ->
266-
let aw = AttributeWriter(Dictionary(), null)
267-
request.ProjectionExpression <- proj.Write aw
268-
request.ExpressionAttributeNames <- aw.Names
266+
let writer = AttributeWriter(Dictionary(), null)
267+
request.ProjectionExpression <- proj.Write writer
268+
request.ExpressionAttributeNames <- writer.Names
269269

270270
match consistentRead with
271271
| None -> ()
@@ -294,7 +294,7 @@ type TableContext<'TRecord>
294294

295295
let consistentRead = defaultArg consistentRead false
296296
let kna = KeysAndAttributes(AttributesToGet = ResizeArray(), Keys = ResizeArray())
297-
kna.AttributesToGet.AddRange(template.Info.Properties |> Seq.map (fun p -> p.Name))
297+
kna.AttributesToGet.AddRange(template.Info.Properties |> Seq.map _.Name)
298298
kna.Keys.AddRange(keys |> Seq.map template.ToAttributeValues)
299299
kna.ConsistentRead <- consistentRead
300300
match projExpr with
@@ -581,7 +581,7 @@ type TableContext<'TRecord>
581581
| true, reqs ->
582582
reqs
583583
|> Seq.choose (fun r -> r.PutRequest |> Option.ofObj)
584-
|> Seq.map (fun w -> w.Item)
584+
|> Seq.map _.Item
585585
|> Seq.toArray
586586
| false, _ -> [||]
587587
maybeReport
@@ -844,7 +844,7 @@ type TableContext<'TRecord>
844844
| true, reqs ->
845845
reqs
846846
|> Seq.choose (fun r -> r.DeleteRequest |> Option.ofObj)
847-
|> Seq.map (fun d -> d.Key)
847+
|> Seq.map _.Key
848848
|> Seq.toArray
849849
| false, _ -> [||]
850850
maybeReport
@@ -873,7 +873,7 @@ type TableContext<'TRecord>
873873
) : Async<'TRecord[]> =
874874
async {
875875

876-
let filterCondition = filterCondition |> Option.map (fun fc -> fc.Conditional)
876+
let filterCondition = filterCondition |> Option.map _.Conditional
877877
let! downloaded = queryAsync keyCondition.Conditional filterCondition None limit consistentRead scanIndexForward
878878
return downloaded |> Seq.map template.OfAttributeValues |> Seq.toArray
879879
}
@@ -922,7 +922,7 @@ type TableContext<'TRecord>
922922
) : Async<'TProjection[]> =
923923
async {
924924

925-
let filterCondition = filterCondition |> Option.map (fun fc -> fc.Conditional)
925+
let filterCondition = filterCondition |> Option.map _.Conditional
926926
let! downloaded = queryAsync keyCondition.Conditional filterCondition None limit consistentRead scanIndexForward
927927
return downloaded |> Seq.map projection.UnPickle |> Seq.toArray
928928
}
@@ -979,7 +979,7 @@ type TableContext<'TRecord>
979979
) : Async<PaginatedResult<'TRecord, IndexKey>> =
980980
async {
981981

982-
let filterCondition = filterCondition |> Option.map (fun fc -> fc.Conditional)
982+
let filterCondition = filterCondition |> Option.map _.Conditional
983983
let! downloaded, lastEvaluatedKey =
984984
queryPaginatedAsync
985985
keyCondition.Conditional
@@ -1048,7 +1048,7 @@ type TableContext<'TRecord>
10481048
) : Async<PaginatedResult<'TProjection, IndexKey>> =
10491049
async {
10501050

1051-
let filterCondition = filterCondition |> Option.map (fun fc -> fc.Conditional)
1051+
let filterCondition = filterCondition |> Option.map _.Conditional
10521052
let! downloaded, lastEvaluatedKey =
10531053
queryPaginatedAsync
10541054
keyCondition.Conditional
@@ -1104,7 +1104,7 @@ type TableContext<'TRecord>
11041104
/// <param name="limit">Maximum number of items to evaluate.</param>
11051105
/// <param name="consistentRead">Specify whether to perform consistent read operation.</param>
11061106
member _.ScanAsync(?filterCondition: ConditionExpression<'TRecord>, ?limit: int, ?consistentRead: bool) : Async<'TRecord[]> = async {
1107-
let filterCondition = filterCondition |> Option.map (fun fc -> fc.Conditional)
1107+
let filterCondition = filterCondition |> Option.map _.Conditional
11081108
let! downloaded = scanAsync filterCondition None limit consistentRead
11091109
return downloaded |> Seq.map template.OfAttributeValues |> Seq.toArray
11101110
}
@@ -1137,7 +1137,7 @@ type TableContext<'TRecord>
11371137
?consistentRead: bool
11381138
) : Async<'TProjection[]> =
11391139
async {
1140-
let filterCondition = filterCondition |> Option.map (fun fc -> fc.Conditional)
1140+
let filterCondition = filterCondition |> Option.map _.Conditional
11411141
let! downloaded = scanAsync filterCondition (Some projection.ProjectionExpr) limit consistentRead
11421142
return downloaded |> Seq.map projection.UnPickle |> Seq.toArray
11431143
}
@@ -1182,7 +1182,7 @@ type TableContext<'TRecord>
11821182
?consistentRead: bool
11831183
) : Async<PaginatedResult<'TRecord, TableKey>> =
11841184
async {
1185-
let filterCondition = filterCondition |> Option.map (fun fc -> fc.Conditional)
1185+
let filterCondition = filterCondition |> Option.map _.Conditional
11861186
let! downloaded, lastEvaluatedKey =
11871187
scanPaginatedAsync filterCondition None (LimitType.DefaultOrCount limit) exclusiveStartKey consistentRead
11881188
return
@@ -1227,7 +1227,7 @@ type TableContext<'TRecord>
12271227
?consistentRead: bool
12281228
) : Async<PaginatedResult<'TProjection, TableKey>> =
12291229
async {
1230-
let filterCondition = filterCondition |> Option.map (fun fc -> fc.Conditional)
1230+
let filterCondition = filterCondition |> Option.map _.Conditional
12311231
let! downloaded, lastEvaluatedKey =
12321232
scanPaginatedAsync
12331233
filterCondition
@@ -1337,11 +1337,11 @@ type TableContext<'TRecord>
13371337
Transaction(client, ?metricsCollector = metricsCollector)
13381338

13391339
/// <summary>
1340-
/// Represents a transactional set of operations to be applied atomically to a arbitrary number of DynamoDB tables.
1340+
/// Represents a transactional set of operations to be applied atomically to an arbitrary number of DynamoDB tables.
13411341
/// </summary>
13421342
/// <param name="client">DynamoDB client instance</param>
13431343
/// <param name="metricsCollector">Function to receive request metrics.</param>
1344-
and Transaction(client: IAmazonDynamoDB, ?metricsCollector: (RequestMetrics -> unit)) =
1344+
and Transaction(client: IAmazonDynamoDB, ?metricsCollector: RequestMetrics -> unit) =
13451345
let transactionItems = ResizeArray<TransactWriteItem>()
13461346

13471347
let reportMetrics collector (tableName: string) (operation: Operation) (consumedCapacity: ConsumedCapacity list) (itemCount: int) =
@@ -1455,7 +1455,7 @@ and Transaction(client: IAmazonDynamoDB, ?metricsCollector: (RequestMetrics -> u
14551455
maybeReport
14561456
|> Option.iter (fun r ->
14571457
response.ConsumedCapacity
1458-
|> Seq.groupBy (fun x -> x.TableName)
1458+
|> Seq.groupBy _.TableName
14591459
|> Seq.iter (fun (tableName, consumedCapacity) ->
14601460
r tableName Operation.TransactWriteItems (Seq.toList consumedCapacity) (Seq.length transactionItems)))
14611461
if response.HttpStatusCode <> HttpStatusCode.OK then

0 commit comments

Comments
 (0)