Skip to content

Commit

Permalink
Int parser
Browse files Browse the repository at this point in the history
  • Loading branch information
Donatas-L committed Jul 27, 2017
1 parent ccc6843 commit b46335b
Show file tree
Hide file tree
Showing 10 changed files with 25 additions and 6 deletions.
Binary file modified .vs/funkylib/v15/.suo
Binary file not shown.
18 changes: 14 additions & 4 deletions Option.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,16 +90,26 @@ public static Option<R> map<A, R>(this Option<A> @this, Func<A, R> func) {
() => Option.None, value => Option.Some(func(value)));
}

public static Option<A> orElse<A>(this Option<A> @this, Func<Option<A>> optional) => !@this.isSome ? optional() : @this;
public static Option<C> orElse<A,B,C>(this Option<A> @this, Func<Option<B>> optional, Func<A,C> mapThis, Func<B,C> mapAnother) {
if (@this.isSome)
return mapThis(@this._unsafe);
else {
var another = optional();
if (another.isSome)
return mapAnother(another._unsafe);
else
return Option.None;
}
}

public static bool exist<A>(this Option<A> @this, Option<A> other) =>
public static bool exist<A>(this Option<A> @this, Option<A> other) =>
@this.fold(
() => false,
left => other.fold(
() => false,
right => left.Equals(right)
)
);
)
);

public static Option<R> flatMap<A, R>(this Option<A> @this, Func<A, Option<R>> func) {
return @this.fold(
Expand Down
8 changes: 8 additions & 0 deletions ValueTypes/Int.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace funkylib.ValueTypes {
public static class Int {
public static Option<int> parse(string s) {
int temp;
return int.TryParse(s, out temp) ? temp.some() : Option.None;
}
}
}
Binary file modified bin/Release/funkylib.dll
Binary file not shown.
Binary file modified bin/Release/funkylib.pdb
Binary file not shown.
2 changes: 1 addition & 1 deletion bin/Release/nunit_random_seed.tmp
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1253614604
1629596981
1 change: 1 addition & 0 deletions funkylib.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
<Compile Include="Try.cs" />
<Compile Include="Validation.cs" />
<Compile Include="ValueTypes\Double.cs" />
<Compile Include="ValueTypes\Int.cs" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
Expand Down
2 changes: 1 addition & 1 deletion obj/Release/CoreCompileInputs.cache
Original file line number Diff line number Diff line change
@@ -1 +1 @@
ba6ea9c893a17fe351c643ce2c126e5673414ff3
f49cd14fa23015f92a2083595c46e8b0c09a9054
Binary file modified obj/Release/funkylib.dll
Binary file not shown.
Binary file modified obj/Release/funkylib.pdb
Binary file not shown.

0 comments on commit b46335b

Please sign in to comment.