Example #1
0
 public static ICachedBlob <A> a <A>(
     ISerializedRW <A> rw, PathStr path, A defaultValue,
     ILog log = null, Log.Level onDeserializeFailureLogLevel = Log.Level.ERROR
     )
 {
     log = log ?? Log.d;
     return(new FileCachedBlob(path).bimap(BiMapper.a(
                                               (byte[] bytes) => {
         var deserializedOpt = rw.deserialize(bytes, 0);
         if (deserializedOpt.isNone)
         {
             if (log.willLog(onDeserializeFailureLogLevel))
             {
                 log.log(
                     onDeserializeFailureLogLevel,
                     $"Can't deserialize {path}, deleting and returning default value."
                     );
             }
             clear(path).getOrLog($"Couldn't clear file: '{path}'", log: log);
             return defaultValue;
         }
         return deserializedOpt.__unsafeGetValue.value;
     },
                                               a => rw.serialize(a).toArray()
                                               )));
 }
Example #2
0
 public static PrefVal <B> bimap <A, B>(
     this PrefVal <A> val, BiMapper <A, B> bimap
     ) => new PrefValMapper <A, B>(val, bimap);
Example #3
0
 public PrefValMapper(PrefVal <A> backing, BiMapper <A, B> bimap)
 {
     this.backing = backing;
     this.bimap   = bimap;
 }
Example #4
0
 public static ICache <B> bimap <A, B>(this ICache <A> cache, BiMapper <A, B> bimap) =>
 new ICacheMapper <A, B>(cache, bimap);
Example #5
0
 public ICacheMapper(ICache <A> backing, BiMapper <A, B> bimap)
 {
     this.backing = backing;
     this.bimap   = bimap;
 }
Example #6
0
 public static ICachedBlob <string> toStringBlob(
     this ICachedBlob <byte[]> blob, Encoding encoding = null
     ) => blob.bimap(BiMapper.byteArrString(encoding));
Example #7
0
 public static ICachedBlob <B> bimap <A, B>(
     this ICachedBlob <A> blob, BiMapper <A, B> bimap
     ) => new ICachedBlobMapper <A, B>(blob, bimap);
Example #8
0
 public ICachedBlobTestBiMap()
 {
     blob       = new ICachedBlobTestImpl <int>();
     mappedBlob = blob.bimap(BiMapper.a <int, string>(i => i.ToString(), int.Parse));
 }