Skip to content

Instantly share code, notes, and snippets.

View devshorts's full-sized avatar

Anton Kropp devshorts

View GitHub Profile
@devshorts
devshorts / gist:7423807
Last active December 28, 2015 01:49
Create stream from iterable in java 8
public class StreamUtil<T>{
public static <T> Stream<T> ofIterable(Iterable<T> iter){
Iterator<T> iterator = iter.iterator();
Stream.Builder<T> builder = Stream.builder();
while(iterator.hasNext()){
builder.add(iterator.next());
}
@devshorts
devshorts / gist:6399857
Created August 31, 2013 18:31
Find a subset of a sequence or an array in F# given a source collection and a target collection
module x
let list = [-1;0;1;2;3;4;5;6;7;8;9] |> List.toArray
let target = [1;2;3] |> List.toArray
let nope = [4;1;2] |> List.toArray
/// <summary>
/// Sequenes are basically IEnumerable, so you can't do structural equality on them
/// this is why they are converted to an F# list before doing comparison, otherwise
/// their references are compared
@devshorts
devshorts / gist:6359736
Last active December 21, 2015 20:09
Crappy discriminated union filtering
let result = test parserStream video
let moov = List.find(function | MOOV(x) -> true | _ -> false) result
let sttsElements =
match moov with
| MOOV(l) ->
List.filter (function | TRAK(_) -> true | _ -> false) l
|> List.map (function | TRAK(l) -> l)
|> List.collect id