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() ))); }
public static PrefVal <B> bimap <A, B>( this PrefVal <A> val, BiMapper <A, B> bimap ) => new PrefValMapper <A, B>(val, bimap);
public PrefValMapper(PrefVal <A> backing, BiMapper <A, B> bimap) { this.backing = backing; this.bimap = bimap; }
public static ICache <B> bimap <A, B>(this ICache <A> cache, BiMapper <A, B> bimap) => new ICacheMapper <A, B>(cache, bimap);
public ICacheMapper(ICache <A> backing, BiMapper <A, B> bimap) { this.backing = backing; this.bimap = bimap; }
public static ICachedBlob <string> toStringBlob( this ICachedBlob <byte[]> blob, Encoding encoding = null ) => blob.bimap(BiMapper.byteArrString(encoding));
public static ICachedBlob <B> bimap <A, B>( this ICachedBlob <A> blob, BiMapper <A, B> bimap ) => new ICachedBlobMapper <A, B>(blob, bimap);
public ICachedBlobTestBiMap() { blob = new ICachedBlobTestImpl <int>(); mappedBlob = blob.bimap(BiMapper.a <int, string>(i => i.ToString(), int.Parse)); }