Skip to content

Commit 0804baf

Browse files
committed
revert
1 parent dcef3cf commit 0804baf

File tree

1 file changed

+18
-20
lines changed

1 file changed

+18
-20
lines changed

cachematrix.R

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,21 @@
44
# mci <- makeCacheMatrix({message("calculating");solve(m)})
55
# cacheSolve(mci)
66
# cacheSolve(mci) # should not print message again, should insted inform about cache use
7-
# mcs <- makeCacheMatrix(solve(m,c(1,1))
7+
# mcs <- makeCacheMatrix(m, c(1,1))
88
# cacheSolve(mcs)
99

1010
# Class for creating matrices with
1111
# ability to cache results of operations
12-
# see CacheOps$help(getResult)
1312
CachedOps <- setRefClass("CachedOps",
14-
fields = list(result = "function", cached = "logical"),
13+
fields = list( func = "function", cache = "ANY"),
1514

1615
methods = list(
17-
initialize = function(expr,...){
18-
cached <<- FALSE
19-
result <<- function(){
20-
cached <<- TRUE
21-
expr
22-
}
23-
callSuper(...)
16+
initialize = function(...,func){
17+
cache <<- NULL
18+
func <<- function(){
19+
func(...)
20+
}
21+
callSuper()
2422
},
2523

2624
getResult = function(){
@@ -31,17 +29,17 @@ Once it was calculated result is cached and returned in any consecutive call"
3129
})
3230
)
3331

34-
makeCacheMatrix <- function(expr,...) {
35-
# Creating new caching object
36-
# Args:
37-
# func - function, result of calculation is need to cache
38-
# ... - parameters for function calling
39-
CachedOps$new(expr,...)
32+
makeCacheMatrix <- function(..., func = solve) {
33+
# Creating new caching object
34+
# Args:
35+
# func - function, result of calculation is need to cache
36+
# ... - parameters for function calling
37+
CachedOps$new(..., func = func)
4038
}
4139

42-
cacheSolve <- function(x) {
43-
# Calculating result of function on matrix
44-
# once it was calculated result is cached
45-
# and returned in any consecutive call
40+
cacheSolve <- function(x, ...) {
41+
# Calculating result of function on matrix
42+
# once it was calculated result is cached
43+
# and returned in any consecutive call
4644
x$getResult()
4745
}

0 commit comments

Comments
 (0)