-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathfluent_wait_exercise.ps1
57 lines (47 loc) · 1.69 KB
/
fluent_wait_exercise.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
$data = @(
'apple',
'orange',
'pear',
'plum'
)
$text = 'pear'
$exact_find = [Boolean](
[Array]::Find($data,[System.Predicate[String]]{
return ($args[0] -eq $text)
}))
write-output $exact_find
# NOTE: '-contains' method is is not doing what it name says
# https://docs.microsoft.com/en-us/dotnet/api/system.array.findall?view=netframework-4.0
#
$match_find = [Boolean](
[Array]::Find($data,[System.Predicate[String]]{
return ($args[0] -match $text)
}))
write-output ('match_find(boolean): {0}' -f $match_find)
# the default is return the matching values
$text = 'e'
$matching_elements = (
[Array]::FindAll($data,[System.Predicate[String]]{
return ($args[0] -match $text)
}))
write-output ('matching_elements(array) of {0}: {1}' -f $text, ($matching_elements -join ','))
$text = 'pear'
# this is not really needed with System.Array.Find but will preactice with plan touse with Wait.Util
$matching_element = [String](
[Array]::Find($data,[System.Predicate[String]]<# follows the code block #>{
if ($text -match $args[0]) { return $args[0] } else { return $null }
}))
write-output ('another matching_element: {0}' -f $matching_element)
# NOTE: strong plain.net type
[String[]]$data = @(
'apple',
'orange',
'pear',
'plum'
)
# both signatures are accepted
write-output 'select example'
[System.Linq.Enumerable]::Select($data,[Func[String,String]] <# follows the code block #> { return $args[0].ToUpper()})
[System.Linq.Enumerable]::Select($data,[System.Func[[String],[String]]] <# follows the code block #> { return $args[0].ToUpper()})
write-output 'where example'
[System.Linq.Enumerable]::Where($data,[Func[String,Bool]] <# follows the code block #> { return $args[0].ToLower() -match $text })