File tree Expand file tree Collapse file tree 1 file changed +11
-9
lines changed Expand file tree Collapse file tree 1 file changed +11
-9
lines changed Original file line number Diff line number Diff line change 5
5
# # ability to cache results of operations
6
6
7
7
CachedOpsMatrix <- setRefClass(" CachedOpsMatrix" ,
8
- fields = list (
9
- value = " matrix" ,
10
- inverse = function (){
11
- if (is.null(my.inverse ))
12
- my.inverse <<- solve(value )
13
- else message(" getting cached data" )
14
- my.inverse
15
- }),
8
+ fields = list (value = " matrix" ),
9
+
16
10
methods = list (
17
11
initialize = function (... ){
18
12
my.inverse <<- NULL
19
13
callSuper(... )
14
+ },
15
+
16
+ getInverse = function (){
17
+ " Calculating inverse of matrix. Once it was calculated result is cached and returned in any consecutive call"
18
+ if (is.null(my.inverse ))
19
+ my.inverse <<- solve(value )
20
+ else message(" getting cached data" )
21
+ my.inverse
20
22
})
21
23
)
22
24
@@ -32,5 +34,5 @@ makeCacheMatrix <- function(x = matrix()) {
32
34
# # and returned in any consecutive call
33
35
34
36
cacheSolve <- function (x , ... ) {
35
- x $ inverse
37
+ x $ getInverse()
36
38
}
You can’t perform that action at this time.
0 commit comments